* bignum.c (bignew_1): inline memory allocation.

* bignum.c (bigtrunc): call rb_big_resize() only when needed.

* bignum.c (bigfixize): declare inline.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-05-26 02:19:33 +00:00
Родитель 120d1b493b
Коммит 0acedf8066
2 изменённых файлов: 20 добавлений и 6 удалений

Просмотреть файл

@ -2,6 +2,14 @@ Tue May 26 11:01:41 2009 TAKANO Mitsuhiro (takano32) <tak@no32.tk>
* lib/mkmf.rb: use map! to replace strings in $objs array.
Tue May 26 10:12:08 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (bignew_1): inline memory allocation.
* bignum.c (bigtrunc): call rb_big_resize() only when needed.
* bignum.c (bigfixize): declare inline.
Tue May 26 05:39:28 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h (FilePathValue): prevent from GC.

Просмотреть файл

@ -132,7 +132,8 @@ bignew_1(VALUE klass, long len, int sign)
RBIGNUM_SET_LEN(big, len);
}
else {
rb_big_resize((VALUE)big, len);
RBIGNUM(big)->as.heap.digits = ALLOC_N(BDIGIT, len);
RBIGNUM(big)->as.heap.len = len;
}
return (VALUE)big;
@ -186,11 +187,13 @@ bigtrunc(VALUE x)
if (len == 0) return x;
while (--len && !ds[len]);
if (RBIGNUM_LEN(x) > len+1) {
rb_big_resize(x, len+1);
}
return x;
}
static VALUE
static inline VALUE
bigfixize(VALUE x)
{
long len = RBIGNUM_LEN(x);
@ -2392,7 +2395,8 @@ rb_big_fdiv(VALUE x, VALUE y)
VALUE z;
int ex, ey;
ex = (RBIGNUM_LEN(bigtrunc(x)) - 1) * BITSPERDIG;
bigtrunc(x);
ex = (RBIGNUM_LEN(x) - 1) * BITSPERDIG;
ex += bdigbitsize(BDIGITS(x)[RBIGNUM_LEN(x) - 1]);
ex -= 2 * DBL_BIGDIG * BITSPERDIG;
if (ex) x = big_shift(x, ex);
@ -2401,7 +2405,8 @@ rb_big_fdiv(VALUE x, VALUE y)
case T_FIXNUM:
y = rb_int2big(FIX2LONG(y));
case T_BIGNUM: {
ey = (RBIGNUM_LEN(bigtrunc(y)) - 1) * BITSPERDIG;
bigtrunc(y);
ey = (RBIGNUM_LEN(y) - 1) * BITSPERDIG;
ey += bdigbitsize(BDIGITS(y)[RBIGNUM_LEN(y) - 1]);
ey -= DBL_BIGDIG * BITSPERDIG;
if (ey) y = big_shift(y, ey);
@ -2875,7 +2880,8 @@ rb_big_aref(VALUE x, VALUE y)
if (TYPE(y) == T_BIGNUM) {
if (!RBIGNUM_SIGN(y))
return INT2FIX(0);
if (RBIGNUM_LEN(bigtrunc(y)) > DIGSPERLONG) {
bigtrunc(y);
if (RBIGNUM_LEN(y) > DIGSPERLONG) {
out_of_range:
return RBIGNUM_SIGN(x) ? INT2FIX(0) : INT2FIX(1);
}