diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-17 00:18:16 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-17 00:18:16 +0000 |
commit | 35cb0f807b4689b0405dfbb2821e13f14c1fca45 (patch) | |
tree | 70c0d395007ea24074b188c0b84203f725501100 /string.c | |
parent | 71c5e485989cfead51f62f36d0d694cab65f855f (diff) | |
download | ruby-35cb0f807b4689b0405dfbb2821e13f14c1fca45.tar.gz |
* string.c (rb_str_times): reduce loop overhead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -762,7 +762,7 @@ VALUE rb_str_times(VALUE str, VALUE times) { VALUE str2; - long i, len; + long n, len; len = NUM2LONG(times); if (len < 0) { @@ -773,9 +773,14 @@ rb_str_times(VALUE str, VALUE times) } str2 = rb_str_new5(str, 0, len *= RSTRING_LEN(str)); - for (i = 0; i < len; i += RSTRING_LEN(str)) { - memcpy(RSTRING_PTR(str2) + i, - RSTRING_PTR(str), RSTRING_LEN(str)); + if (len) { + n = RSTRING_LEN(str); + memcpy(RSTRING_PTR(str2), RSTRING_PTR(str), n); + while (n <= len/2) { + memcpy(RSTRING_PTR(str2) + n, RSTRING_PTR(str2), n); + n *= 2; + } + memcpy(RSTRING_PTR(str2) + n, RSTRING_PTR(str2), len-n); } RSTRING_PTR(str2)[RSTRING_LEN(str2)] = '\0'; OBJ_INFECT(str2, str); |