diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-07 23:12:55 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-07 23:12:55 +0000 |
commit | 9ebd008f324aeb2f4b7017e30c75629fe7441d19 (patch) | |
tree | 1a878440d12e3d82433634fa7fce7c6535383c59 | |
parent | 97b5a9c1025e583099aa624bcab0251f2e7aae96 (diff) | |
download | ruby-9ebd008f324aeb2f4b7017e30c75629fe7441d19.tar.gz |
* random.c (random_load): Use rb_integer_pack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | random.c | 47 |
2 files changed, 7 insertions, 44 deletions
@@ -1,3 +1,7 @@ +Sat Jun 8 08:12:22 2013 Tanaka Akira <akr@fsij.org> + + * random.c (random_load): Use rb_integer_pack. + Sat Jun 8 06:15:46 2013 Tanaka Akira <akr@fsij.org> * random.c (numberof): Removed. @@ -690,50 +690,9 @@ random_load(VALUE obj, VALUE dump) default: rb_raise(rb_eArgError, "wrong dump data"); } - memset(mt->state, 0, sizeof(mt->state)); - if (FIXNUM_P(state)) { - x = FIX2ULONG(state); - mt->state[0] = (unsigned int)x; -#if SIZEOF_LONG / SIZEOF_INT >= 2 - mt->state[1] = (unsigned int)(x >> (sizeof(int) * CHAR_BIT)); -#endif -#if SIZEOF_LONG / SIZEOF_INT >= 3 - mt->state[2] = (unsigned int)(x >> 2 * (sizeof(int) * CHAR_BIT)); -#endif -#if SIZEOF_LONG / SIZEOF_INT >= 4 - mt->state[3] = (unsigned int)(x >> 3 * (sizeof(int) * CHAR_BIT)); -#endif - } - else { - BDIGIT *dp, *de; - unsigned int *sp, *se; - BDIGIT_DBL dd; - int numbytes_in_dd; - Check_Type(state, T_BIGNUM); - dp = RBIGNUM_DIGITS(state); - de = dp + RBIGNUM_LEN(state); - sp = mt->state; - se = sp + sizeof(mt->state) / sizeof(*mt->state);; - dd = 0; - numbytes_in_dd = 0; - while (dp < de && sp < se) { - while (dp < de && SIZEOF_BDIGITS <= (int)sizeof(dd) - numbytes_in_dd) { - dd |= (BDIGIT_DBL)(*dp++) << (numbytes_in_dd * CHAR_BIT); - numbytes_in_dd += SIZEOF_BDIGITS; - } - while (sp < se && (int)sizeof(int) <= numbytes_in_dd) { - *sp++ = (unsigned int)dd; - if (sizeof(dd) == sizeof(int)) - dd = 0; - else - dd >>= SIZEOF_INT * CHAR_BIT; - numbytes_in_dd -= SIZEOF_INT; - } - } - if (numbytes_in_dd && sp < se) { - *sp = (unsigned int)dd; - } - } + rb_integer_pack(state, NULL, NULL, mt->state, numberof(mt->state), + sizeof(*mt->state), 0, + INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER); x = NUM2ULONG(left); if (x > numberof(mt->state)) { rb_raise(rb_eArgError, "wrong value"); |