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

ruby-changes:14769

From: matz <ko1@a...>
Date: Wed, 10 Feb 2010 13:05:27 +0900 (JST)
Subject: [ruby-changes:14769] Ruby:r26630 (ruby_1_8): * string.c (rb_str_times): backport r15514 to reduce loop

matz	2010-02-10 13:05:15 +0900 (Wed, 10 Feb 2010)

  New Revision: 26630

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

  Log:
    * string.c (rb_str_times): backport r15514 to reduce loop
      overhead.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/string.c

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 26629)
+++ ruby_1_8/ChangeLog	(revision 26630)
@@ -1,3 +1,8 @@
+Wed Feb 10 13:03:29 2010  Yukihiro Matsumoto  <matz@r...>
+
+	* string.c (rb_str_times): backport r15514 to reduce loop
+	  overhead.
+
 Sun Feb  7 04:02:08 2010  Akinori MUSHA  <knu@i...>
 
 	* parse.y: Get rid of tags for Ripper, pointless in 1.8.
Index: ruby_1_8/string.c
===================================================================
--- ruby_1_8/string.c	(revision 26629)
+++ ruby_1_8/string.c	(revision 26630)
@@ -428,7 +428,8 @@
     VALUE times;
 {
     VALUE str2;
-    long i, len;
+    long n, len;
+    char *ptr2;
 
     len = NUM2LONG(times);
     if (len < 0) {
@@ -439,12 +440,17 @@
     }
 
     str2 = rb_str_new5(str,0, len *= RSTRING(str)->len);
-    for (i = 0; i < len; i += RSTRING(str)->len) {
-	memcpy(RSTRING(str2)->ptr + i,
-	       RSTRING(str)->ptr, RSTRING(str)->len);
+    ptr2 = RSTRING_PTR(str2);
+    if (len) {
+        n = RSTRING_LEN(str);
+        memcpy(ptr2, RSTRING_PTR(str), n);
+        while (n <= len/2) {
+            memcpy(ptr2 + n, ptr2, n);
+            n *= 2;
+        }
+        memcpy(ptr2 + n, ptr2, len-n);
     }
-    RSTRING(str2)->ptr[RSTRING(str2)->len] = '\0';
-
+    ptr2[RSTRING_LEN(str2)] = '\0';
     OBJ_INFECT(str2, str);
 
     return str2;

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

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