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

ruby-changes:34982

From: nobu <ko1@a...>
Date: Mon, 4 Aug 2014 22:27:07 +0900 (JST)
Subject: [ruby-changes:34982] nobu:r47064 (trunk): pack.c (encodes): name a magic number

nobu	2014-08-04 22:27:01 +0900 (Mon, 04 Aug 2014)

  New Revision: 47064

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

  Log:
    pack.c (encodes): name a magic number

  Modified files:
    trunk/pack.c
Index: pack.c
===================================================================
--- pack.c	(revision 47063)
+++ pack.c	(revision 47064)
@@ -945,10 +945,10 @@ static const char b64_table[] = https://github.com/ruby/ruby/blob/trunk/pack.c#L945
 static void
 encodes(VALUE str, const char *s, long len, int type, int tail_lf)
 {
-    enum {buff_size = 4096, encoded_unit = 4};
+    enum {buff_size = 4096, encoded_unit = 4, input_unit = 3};
     char buff[buff_size + 1];	/* +1 for tail_lf */
     long i = 0;
-    const char *trans = type == 'u' ? uu_table : b64_table;
+    const char *const trans = type == 'u' ? uu_table : b64_table;
     char padding;
 
     if (type == 'u') {
@@ -958,14 +958,14 @@ encodes(VALUE str, const char *s, long l https://github.com/ruby/ruby/blob/trunk/pack.c#L958
     else {
 	padding = '=';
     }
-    while (len >= 3) {
-        while (len >= 3 && buff_size-i >= encoded_unit) {
+    while (len >= input_unit) {
+        while (len >= input_unit && buff_size-i >= encoded_unit) {
             buff[i++] = trans[077 & (*s >> 2)];
             buff[i++] = trans[077 & (((*s << 4) & 060) | ((s[1] >> 4) & 017))];
             buff[i++] = trans[077 & (((s[1] << 2) & 074) | ((s[2] >> 6) & 03))];
             buff[i++] = trans[077 & s[2]];
-            s += 3;
-            len -= 3;
+            s += input_unit;
+            len -= input_unit;
         }
         if (buff_size-i < encoded_unit) {
             rb_str_buf_cat(str, buff, i);

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

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