aboutsummaryrefslogtreecommitdiffstats
path: root/pack.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 21:20:04 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 21:20:04 +0000
commitc9c67d2fe0d8d502d444c477d3272c4092513a53 (patch)
tree81a21632cffe836b8e768ed733eedcbfd999426a /pack.c
parent64ed7df5434bc2978d5a92a1e750bab39b11edfa (diff)
downloadruby-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.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/pack.c b/pack.c
index 1d51bebe48..d77ed999b4 100644
--- a/pack.c
+++ b/pack.c
@@ -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;