1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2011-01-17 14:37:05 +00:00
parent 099f52d73d
commit 355c3a250d
2 changed files with 14 additions and 3 deletions

View file

@ -1,3 +1,7 @@
Mon Jan 17 23:36:33 2011 Tanaka Akira <akr@fsij.org>
* array.c (rb_ary_times): less MEMCPY calls.
Mon Jan 17 22:54:33 2011 Tanaka Akira <akr@fsij.org> Mon Jan 17 22:54:33 2011 Tanaka Akira <akr@fsij.org>
* debug.h: parenthesize macro arguments. * debug.h: parenthesize macro arguments.

13
array.c
View file

@ -2988,7 +2988,7 @@ static VALUE
rb_ary_times(VALUE ary, VALUE times) rb_ary_times(VALUE ary, VALUE times)
{ {
VALUE ary2, tmp, *ptr, *ptr2; VALUE ary2, tmp, *ptr, *ptr2;
long i, t, len; long t, len;
tmp = rb_check_string_type(times); tmp = rb_check_string_type(times);
if (!NIL_P(tmp)) { if (!NIL_P(tmp)) {
@ -3014,8 +3014,15 @@ rb_ary_times(VALUE ary, VALUE times)
ptr = RARRAY_PTR(ary); ptr = RARRAY_PTR(ary);
ptr2 = RARRAY_PTR(ary2); ptr2 = RARRAY_PTR(ary2);
t = RARRAY_LEN(ary); t = RARRAY_LEN(ary);
for (i=0; i<len; i+=t) { if (0 < t) {
MEMCPY(ptr2+i, ptr, VALUE, 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: out:
OBJ_INFECT(ary2, ary); OBJ_INFECT(ary2, ary);