summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-17 14:37:05 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-17 14:37:05 +0000
commit355c3a250ddd0b8ea012cf5e3c4bacc960b28284 (patch)
treeabf2209dee7ff58f56c8d52a9c719511ac8b068e /array.c
parent099f52d73d2a0ee2faae355cb5286a79048bda0e (diff)
* array.c (rb_ary_times): less MEMCPY calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/array.c b/array.c
index 51ec2f9910..7624e1ffe5 100644
--- a/array.c
+++ b/array.c
@@ -2988,7 +2988,7 @@ static VALUE
rb_ary_times(VALUE ary, VALUE times)
{
VALUE ary2, tmp, *ptr, *ptr2;
- long i, t, len;
+ long t, len;
tmp = rb_check_string_type(times);
if (!NIL_P(tmp)) {
@@ -3014,8 +3014,15 @@ rb_ary_times(VALUE ary, VALUE times)
ptr = RARRAY_PTR(ary);
ptr2 = RARRAY_PTR(ary2);
t = RARRAY_LEN(ary);
- for (i=0; i<len; i+=t) {
- MEMCPY(ptr2+i, ptr, VALUE, t);
+ if (0 < t) {
+ MEMCPY(ptr2, ptr, VALUE, t);
+ while (t <= len/2) {
+ MEMCPY(ptr2+t, ptr2, VALUE, t);
+ t *= 2;
+ }
+ if (t < len) {
+ MEMCPY(ptr2+t, ptr2, VALUE, len-t);
+ }
}
out:
OBJ_INFECT(ary2, ary);