From 75a86e4733faf3f5a26aa08745e407c061d178c3 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 13 Jul 2013 15:36:18 +0000 Subject: * bignum.c (rb_big_aref): Less scan when the number is negative. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index fb3954624c..9a4d032e42 100644 --- a/bignum.c +++ b/bignum.c @@ -5889,9 +5889,9 @@ static VALUE rb_big_aref(VALUE x, VALUE y) { BDIGIT *xds; - BDIGIT_DBL num; unsigned long shift; long i, s1, s2; + BDIGIT bit; if (RB_TYPE_P(y, T_BIGNUM)) { if (!RBIGNUM_SIGN(y)) @@ -5910,21 +5910,19 @@ rb_big_aref(VALUE x, VALUE y) } s1 = shift/BITSPERDIG; s2 = shift%BITSPERDIG; + bit = (BDIGIT)1 << s2; if (s1 >= RBIGNUM_LEN(x)) goto out_of_range; - if (!RBIGNUM_SIGN(x)) { - xds = BDIGITS(x); - i = 0; num = 1; - while (num += BIGLO(~xds[i]), ++i <= s1) { - num = BIGDN(num); - } - } - else { - num = BDIGITS(x)[s1]; - } - if (num & ((BDIGIT_DBL)1<