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

ruby-changes:40369

From: nobu <ko1@a...>
Date: Wed, 4 Nov 2015 16:50:42 +0900 (JST)
Subject: [ruby-changes:40369] nobu:r52450 (trunk): tkutil.c: rb_ary_cat

nobu	2015-11-04 16:50:34 +0900 (Wed, 04 Nov 2015)

  New Revision: 52450

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

  Log:
    tkutil.c: rb_ary_cat
    
    * ext/tk/tkutil/tkutil.c (rb_ary_cat): fallback definition.
      rb_ary_cat() is available since 2.0.

  Modified files:
    trunk/ext/tk/tkutil/extconf.rb
    trunk/ext/tk/tkutil/tkutil.c
Index: ext/tk/tkutil/extconf.rb
===================================================================
--- ext/tk/tkutil/extconf.rb	(revision 52449)
+++ ext/tk/tkutil/extconf.rb	(revision 52450)
@@ -6,6 +6,7 @@ begin https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/extconf.rb#L6
   have_func("rb_obj_taint", "ruby.h")
   have_func("rb_sym2str", "ruby.h")
   have_func("rb_id2str", "ruby.h")
+  have_func("rb_ary_cat", "ruby.h")
   have_func("strndup", "string.h")
 
   create_makefile('tkutil')
Index: ext/tk/tkutil/tkutil.c
===================================================================
--- ext/tk/tkutil/tkutil.c	(revision 52449)
+++ ext/tk/tkutil/tkutil.c	(revision 52450)
@@ -106,6 +106,22 @@ strndup(ptr, len) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L106
 }
 #endif
 
+#ifndef HAVE_RB_ARY_CAT
+static VALUE rb_ary_cat _((VALUE, const VALUE *, long));
+static VALUE
+rb_ary_cat(ary, argv, len)
+    VALUE ary;
+    const VALUE *argv;
+    long len;
+{
+    long i;
+    for (i = 0; i < len; i++) {
+	rb_ary_push(ary, argv[i]);
+    }
+    return ary;
+}
+#endif
+
 /*************************************/
 
 #if defined(HAVE_RB_OBJ_INSTANCE_EXEC) && !defined(RUBY_VM)
@@ -584,7 +600,7 @@ assoc2kv(assoc, ary, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L600
     VALUE ary;
     VALUE self;
 {
-    long i, j, len;
+    long i, len;
     volatile VALUE pair;
     volatile VALUE val;
     volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
@@ -611,9 +627,7 @@ assoc2kv(assoc, ary, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L627
             rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0]));
 
             val = rb_ary_new2(RARRAY_LEN(pair) - 1);
-            for(j = 1; j < RARRAY_LEN(pair); j++) {
-                rb_ary_push(val, RARRAY_CONST_PTR(pair)[j]);
-            }
+            rb_ary_cat(val, RARRAY_CONST_PTR(pair) + 1, RARRAY_LEN(pair) - 1);
 
             rb_ary_push(dst, val);
         }
@@ -632,7 +646,7 @@ assoc2kv_enc(assoc, ary, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L646
     VALUE ary;
     VALUE self;
 {
-    long i, j, len;
+    long i, len;
     volatile VALUE pair;
     volatile VALUE val;
     volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
@@ -659,9 +673,7 @@ assoc2kv_enc(assoc, ary, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L673
             rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0]));
 
             val = rb_ary_new2(RARRAY_LEN(pair) - 1);
-            for(j = 1; j < RARRAY_LEN(pair); j++) {
-                rb_ary_push(val, RARRAY_CONST_PTR(pair)[j]);
-            }
+            rb_ary_cat(val, RARRAY_CONST_PTR(pair) + 1, RARRAY_LEN(pair) - 1);
 
             rb_ary_push(dst, get_eval_string_core(val, Qtrue, self));
         }

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

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