From ec9089637eea240b60bb340bf82737926c753a84 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 5 Oct 2009 14:35:39 +0000 Subject: * array.c (rb_ary_{times, shuffle_bang, sample}): reducing macro calls inside of the loop by keeping pointers in local variables. a patch from Masahiro Kanai (CanI) in [ruby-dev:39406]. It was found and fixed at Security and Programming camp 2009. * string.c (rb_str_{times, split_m}): ditto. * struct.c (rb_struct_{getmember, set, aref_id, aset_id}, {make, inspect}_struct, recursive_{equal, hash, eql}): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++ array.c | 31 ++++++++++++------- string.c | 27 ++++++++++------- struct.c | 100 +++++++++++++++++++++++++++++++++++++++----------------------- 4 files changed, 111 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6c4dc09a0..4f1117bd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon Oct 5 12:22:12 2009 Yukihiro Matsumoto + + * array.c (rb_ary_{times, shuffle_bang, sample}): reducing macro + calls inside of the loop by keeping pointers in local + variables. a patch from Masahiro Kanai (CanI) in [ruby-dev:39406]. + It was found and fixed at Security and Programming camp 2009. + + * string.c (rb_str_{times, split_m}): ditto. + + * struct.c (rb_struct_{getmember, set, aref_id, aset_id}, {make, + inspect}_struct, recursive_{equal, hash, eql}): ditto. + Mon Oct 5 00:09:57 2009 Yukihiro Matsumoto * vm_method.c (basic_obj_respond_to): should not call diff --git a/array.c b/array.c index f1844b0fc..05d5494af 100644 --- a/array.c +++ b/array.c @@ -2708,8 +2708,8 @@ rb_ary_concat(VALUE x, VALUE y) static VALUE rb_ary_times(VALUE ary, VALUE times) { - VALUE ary2, tmp; - long i, len; + VALUE ary2, tmp, *ptr, *ptr2; + long i, t, len; tmp = rb_check_string_type(times); if (!NIL_P(tmp)) { @@ -2732,8 +2732,11 @@ rb_ary_times(VALUE ary, VALUE times) ary2 = ary_new(rb_obj_class(ary), len); ARY_SET_LEN(ary2, len); - for (i=0; i= 0) { regs = RMATCH_REGS(rb_backref_get()); if (start == end && BEG(0) == END(0)) { - if (!RSTRING_PTR(str)) { + if (!ptr) { rb_ary_push(result, rb_str_new("", 0)); break; } else if (last_null == 1) { rb_ary_push(result, rb_str_subseq(str, beg, - rb_enc_fast_mbclen(RSTRING_PTR(str)+beg, - RSTRING_END(str), + rb_enc_fast_mbclen(ptr+beg, + ptr+len, enc))); beg = start; } else { - if (RSTRING_PTR(str)+start == RSTRING_END(str)) + if (ptr+start == ptr+len) start++; else - start += rb_enc_fast_mbclen(RSTRING_PTR(str)+start,RSTRING_END(str),enc); + start += rb_enc_fast_mbclen(ptr+start,ptr+len,enc); last_null = 1; continue; } diff --git a/struct.c b/struct.c index 0001ad825..0a0f21754 100644 --- a/struct.c +++ b/struct.c @@ -98,14 +98,17 @@ rb_struct_members_m(VALUE obj) VALUE rb_struct_getmember(VALUE obj, ID id) { - VALUE members, slot; - long i; + VALUE members, slot, *ptr, *ptr_members; + long i, len; + ptr = RSTRUCT_PTR(obj); members = rb_struct_members(obj); + ptr_members = RARRAY_PTR(members); slot = ID2SYM(id); - for (i=0; i"); OBJ_INFECT(str, s); @@ -588,14 +600,16 @@ rb_struct_init_copy(VALUE copy, VALUE s) static VALUE rb_struct_aref_id(VALUE s, ID id) { - VALUE members; + VALUE *ptr, members, *ptr_members; long i, len; + ptr = RSTRUCT_PTR(s); members = rb_struct_members(s); + ptr_members = RARRAY_PTR(members); len = RARRAY_LEN(members); for (i=0; i