[前][次][番号順一覧][スレッド一覧]

ruby-changes:29197

From: akr <ko1@a...>
Date: Wed, 12 Jun 2013 12:36:09 +0900 (JST)
Subject: [ruby-changes:29197] akr:r41249 (trunk): * pack.c (pack_pack): Use rb_integer_pack_2comp.

akr	2013-06-12 12:35:54 +0900 (Wed, 12 Jun 2013)

  New Revision: 41249

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41249

  Log:
    * pack.c (pack_pack): Use rb_integer_pack_2comp.

  Modified files:
    trunk/ChangeLog
    trunk/pack.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41248)
+++ ChangeLog	(revision 41249)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun 12 12:35:13 2013  Tanaka Akira  <akr@f...>
+
+	* pack.c (pack_pack): Use rb_integer_pack_2comp.
+
 Wed Jun 12 12:07:04 2013  Tanaka Akira  <akr@f...>
 
 	* sprintf.c (rb_str_format): Fix a dynamic format string.
Index: pack.c
===================================================================
--- pack.c	(revision 41248)
+++ pack.c	(revision 41249)
@@ -796,31 +796,12 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L796
                 if (integer_size > MAX_INTEGER_PACK_SIZE)
                     rb_bug("unexpected intger size for pack: %d", integer_size);
                 while (len-- > 0) {
-                    union {
-                        unsigned long i[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG-1)/SIZEOF_LONG];
-                        char a[(MAX_INTEGER_PACK_SIZE+SIZEOF_LONG-1)/SIZEOF_LONG*SIZEOF_LONG];
-                    } v;
-                    int num_longs = (integer_size+SIZEOF_LONG-1)/SIZEOF_LONG;
-                    int i;
+                    char intbuf[MAX_INTEGER_PACK_SIZE];
 
                     from = NEXTFROM;
-                    rb_big_pack(from, v.i, num_longs);
-                    if (bigendian_p) {
-                        for (i = 0; i < num_longs/2; i++) {
-                            unsigned long t = v.i[i];
-                            v.i[i] = v.i[num_longs-1-i];
-                            v.i[num_longs-1-i] = t;
-                        }
-                    }
-		    if (bigendian_p != BIGENDIAN_P()) {
-                        for (i = 0; i < num_longs; i++)
-                            v.i[i] = swapl(v.i[i]);
-                    }
-                    rb_str_buf_cat(res,
-                                   bigendian_p ?
-                                     v.a + sizeof(long)*num_longs - integer_size :
-                                     v.a,
-                                   integer_size);
+                    rb_integer_pack_2comp(from, intbuf, integer_size, 1, 0,
+                        bigendian_p ? INTEGER_PACK_BIG_ENDIAN : INTEGER_PACK_LITTLE_ENDIAN);
+                    rb_str_buf_cat(res, intbuf, integer_size);
                 }
                 break;
 	    }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]