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

ruby-changes:2175

From: ko1@a...
Date: 9 Oct 2007 18:11:57 +0900
Subject: [ruby-changes:2175] matz - Ruby:r13666 (trunk): * array.c: remove to_a completely.

matz	2007-10-09 18:11:36 +0900 (Tue, 09 Oct 2007)

  New Revision: 13666

  Modified files:
    trunk/ChangeLog
    trunk/array.c

  Log:
    * array.c: remove to_a completely.
    
    * array.c (tmpbuf): keep DRY to clear klass of temporary objects.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=13666&r2=13665
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13666&r2=13665

Index: array.c
===================================================================
--- array.c	(revision 13665)
+++ array.c	(revision 13666)
@@ -231,14 +231,6 @@
     return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
 }
 
-#if 0
-static VALUE
-to_a(VALUE ary)
-{
-    return rb_convert_type(ary, T_ARRAY, "Array", "to_a");
-}
-#endif
-
 VALUE
 rb_check_array_type(VALUE ary)
 {
@@ -2956,6 +2948,15 @@
     return Qnil;
 }
 
+static VALUE
+tmpbuf(int n, int size)
+{
+    VALUE buf = rb_str_new(0, n*size);
+
+    RBASIC(buf)->klass = 0;
+    return buf;
+}
+
 /*
  * Recursively compute permutations of r elements of the set [0..n-1].
  * When we have a complete permutation of array indexes, copy the values
@@ -3039,13 +3040,11 @@
 	}
     }
     else {             /* this is the general case */
-	volatile VALUE t0 = rb_str_new(0, n*sizeof(long));
-	long *p = (long*)RSTRING_PTR(t0); /* array indexes of current permutation */
-	volatile VALUE t1 = rb_str_new(0, n*sizeof(int));
-	int *used = (int*)RSTRING_PTR(t1); /* booleans: which indexes are already used */
+	volatile t0 = tmpbuf(n,sizeof(long));
+	long *p = (long*)RSTRING_PTR(t0);
+	volatile t1 = tmpbuf(n,sizeof(int));
+	int *used = (int*)RSTRING_PTR(t0);
 
-	RBASIC(t0)->klass = 0;
-	RBASIC(t1)->klass = 0;
 	ary = rb_ary_dup(ary); /* private defensive copy of ary */
 
 	for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
@@ -3114,14 +3113,13 @@
 	}
     }
     else {
-	volatile VALUE tmp = rb_str_new(0, n*sizeof(long));
-	long *stack = (long*)RSTRING_PTR(tmp);
+	volatile t0 = tmpbuf(n, sizeof(long));
+	long *stack = (long*)RSTRING_PTR(t0);
 	long nlen = combi_len(len, n);
 	volatile VALUE cc = rb_ary_new2(n);
 	VALUE *chosen = RARRAY_PTR(cc);
 	long lev = 0;
 
-	RBASIC(tmp)->klass = 0;
 	RBASIC(cc)->klass = 0;
 	MEMZERO(stack, long, n);
 	stack[0] = -1;
@@ -3159,8 +3157,8 @@
 rb_ary_product(int argc, VALUE *argv, VALUE ary)
 {
     int n = argc+1;    /* How many arrays we're operating on */
-    volatile VALUE t0 = rb_str_new(0, n*sizeof(VALUE));
-    volatile VALUE t1 = rb_str_new(0, n*sizeof(int));
+    volatile VALUE t0 = tmpbuf(n, sizeof(VALUE));
+    volatile VALUE t1 = tmpbuf(n, sizeof(int));
     VALUE *arrays = (VALUE*)RSTRING_PTR(t0); /* The arrays we're computing the product of */
     int *counters = (int*)RSTRING_PTR(t1); /* The current position in each one */
     VALUE result;      /* The array we'll be returning */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13665)
+++ ChangeLog	(revision 13666)
@@ -1,3 +1,9 @@
+Tue Oct  9 16:58:10 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* array.c: remove to_a completely.
+
+	* array.c (tmpbuf): keep DRY to clear klass of temporary objects.
+
 Tue Oct  9 16:33:32 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* array.c (rb_ary_permutation, rb_ary_combination, rb_ary_product):

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

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