diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-02-10 04:05:15 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-02-10 04:05:15 +0000 |
commit | 255ef3ccac984fb112e129d16ea46d5fb5225186 (patch) | |
tree | 67bfe13c982efc52a8ff11941cd9059b21ca7912 | |
parent | c93458e0e67b0f1ca023e2af6be6abac8fa515ec (diff) |
* string.c (rb_str_times): backport r15514 to reduce loop
overhead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 20 |
2 files changed, 18 insertions, 7 deletions
@@ -1,3 +1,8 @@ +Wed Feb 10 13:03:29 2010 Yukihiro Matsumoto <[email protected]> + + * string.c (rb_str_times): backport r15514 to reduce loop + overhead. + Sun Feb 7 04:02:08 2010 Akinori MUSHA <[email protected]> * parse.y: Get rid of tags for Ripper, pointless in 1.8. @@ -428,7 +428,8 @@ rb_str_times(str, times) VALUE times; { VALUE str2; - long i, len; + long n, len; + char *ptr2; len = NUM2LONG(times); if (len < 0) { @@ -439,12 +440,17 @@ rb_str_times(str, times) } 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); - } - RSTRING(str2)->ptr[RSTRING(str2)->len] = '\0'; - + 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); + } + ptr2[RSTRING_LEN(str2)] = '\0'; OBJ_INFECT(str2, str); return str2; |