ruby-changes:29504
From: akr <ko1@a...>
Date: Sat, 22 Jun 2013 10:39:26 +0900 (JST)
Subject: [ruby-changes:29504] akr:r41556 (trunk): * pack.c (num2i32): Removed.
akr 2013-06-22 10:39:15 +0900 (Sat, 22 Jun 2013) New Revision: 41556 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41556 Log: * pack.c (num2i32): Removed. (pack_pack): Don't use num2i32. Modified files: trunk/ChangeLog trunk/pack.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41555) +++ ChangeLog (revision 41556) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 22 10:38:03 2013 Tanaka Akira <akr@f...> + + * pack.c (num2i32): Removed. + (pack_pack): Don't use num2i32. + Sat Jun 22 09:55:13 2013 Tanaka Akira <akr@f...> * bignum.c (LSHIFTX): Defined to suppress a warning. Index: pack.c =================================================================== --- pack.c (revision 41555) +++ pack.c (revision 41556) @@ -225,20 +225,6 @@ TOKEN_PASTE(swap,x)(xtype z) \ https://github.com/ruby/ruby/blob/trunk/pack.c#L225 # define VTOHD(x,y) rb_vtohd(x) #endif -static unsigned long -num2i32(VALUE x) -{ - x = rb_to_int(x); /* is nil OK? (should not) */ - - if (FIXNUM_P(x)) return FIX2LONG(x); - if (RB_TYPE_P(x, T_BIGNUM)) { - return rb_big2ulong_pack(x); - } - rb_raise(rb_eTypeError, "can't convert %s to `integer'", rb_obj_classname(x)); - - UNREACHABLE; -} - #define MAX_INTEGER_PACK_SIZE 8 /* #define FORCE_BIG_PACK */ @@ -700,82 +686,17 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L686 if (explicit_endian) { bigendian_p = explicit_endian == '>'; } - - switch (integer_size) { -#if !defined(FORCE_BIG_PACK) - case 1: - while (len-- > 0) { - char c; - - from = NEXTFROM; - c = (char)num2i32(from); - rb_str_buf_cat(res, &c, sizeof(char)); - } - break; -#endif - -#if defined(HAVE_INT16_T) && !defined(FORCE_BIG_PACK) - case SIZEOF_INT16_T: - while (len-- > 0) { - union { - int16_t i; - char a[sizeof(int16_t)]; - } v; - - from = NEXTFROM; - v.i = (int16_t)num2i32(from); - if (bigendian_p != BIGENDIAN_P()) v.i = swap16(v.i); - rb_str_buf_cat(res, v.a, sizeof(int16_t)); - } - break; -#endif - -#if defined(HAVE_INT32_T) && !defined(FORCE_BIG_PACK) - case SIZEOF_INT32_T: - while (len-- > 0) { - union { - int32_t i; - char a[sizeof(int32_t)]; - } v; - - from = NEXTFROM; - v.i = (int32_t)num2i32(from); - if (bigendian_p != BIGENDIAN_P()) v.i = swap32(v.i); - rb_str_buf_cat(res, v.a, sizeof(int32_t)); - } - break; -#endif - -#if defined(HAVE_INT64_T) && SIZEOF_LONG == SIZEOF_INT64_T && !defined(FORCE_BIG_PACK) - case SIZEOF_INT64_T: - while (len-- > 0) { - union { - int64_t i; - char a[sizeof(int64_t)]; - } v; - - from = NEXTFROM; - v.i = num2i32(from); /* can return 64bit value if SIZEOF_LONG == SIZEOF_INT64_T */ - if (bigendian_p != BIGENDIAN_P()) v.i = swap64(v.i); - rb_str_buf_cat(res, v.a, sizeof(int64_t)); - } - break; -#endif - - default: - if (integer_size > MAX_INTEGER_PACK_SIZE) - rb_bug("unexpected intger size for pack: %d", integer_size); - while (len-- > 0) { - char intbuf[MAX_INTEGER_PACK_SIZE]; - - from = NEXTFROM; - rb_integer_pack(from, intbuf, integer_size, 1, 0, - INTEGER_PACK_2COMP | - (bigendian_p ? INTEGER_PACK_BIG_ENDIAN : INTEGER_PACK_LITTLE_ENDIAN)); - rb_str_buf_cat(res, intbuf, integer_size); - } - break; - } + if (integer_size > MAX_INTEGER_PACK_SIZE) + rb_bug("unexpected intger size for pack: %d", integer_size); + while (len-- > 0) { + char intbuf[MAX_INTEGER_PACK_SIZE]; + + from = NEXTFROM; + rb_integer_pack(from, intbuf, integer_size, 1, 0, + INTEGER_PACK_2COMP | + (bigendian_p ? INTEGER_PACK_BIG_ENDIAN : INTEGER_PACK_LITTLE_ENDIAN)); + rb_str_buf_cat(res, intbuf, integer_size); + } break; case 'f': /* single precision float in native format */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/