diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-06 21:20:04 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-06 21:20:04 +0000 |
commit | c9c67d2fe0d8d502d444c477d3272c4092513a53 (patch) | |
tree | 81a21632cffe836b8e768ed733eedcbfd999426a /pack.c | |
parent | 64ed7df5434bc2978d5a92a1e750bab39b11edfa (diff) | |
download | ruby-c9c67d2fe0d8d502d444c477d3272c4092513a53.tar.gz |
* bignum.c (rb_int_import): New function.
(int_import_push_bits): Ditto.
* internal.h (rb_int_import): Declared.
* pack.c (pack_unpack): Use rb_int_import for BER compressed integer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r-- | pack.c | 38 |
1 files changed, 12 insertions, 26 deletions
@@ -2137,32 +2137,18 @@ pack_unpack(VALUE str, VALUE fmt) case 'w': { - unsigned long ul = 0; - unsigned long ulmask = 0xfeUL << ((sizeof(unsigned long) - 1) * 8); - - while (len > 0 && s < send) { - ul <<= 7; - ul |= (*s & 0x7f); - if (!(*s++ & 0x80)) { - UNPACK_PUSH(ULONG2NUM(ul)); - len--; - ul = 0; - } - else if (ul & ulmask) { - VALUE big = rb_uint2big(ul); - VALUE big128 = rb_uint2big(128); - while (s < send) { - big = rb_big_mul(big, big128); - big = rb_big_plus(big, rb_uint2big(*s & 0x7f)); - if (!(*s++ & 0x80)) { - UNPACK_PUSH(big); - len--; - ul = 0; - break; - } - } - } - } + char *s0 = s; + while (len > 0 && s < send) { + if (*s & 0x80) { + s++; + } + else { + s++; + UNPACK_PUSH(rb_int_import(1, s0, s-s0, 1, 1, 1, 1)); + len--; + s0 = s; + } + } } break; |