ruby-changes:34923
From: nobu <ko1@a...>
Date: Wed, 30 Jul 2014 22:46:52 +0900 (JST)
Subject: [ruby-changes:34923] nobu:r47006 (trunk): get rid of function calls in RSTRING_PTR
nobu 2014-07-30 22:46:41 +0900 (Wed, 30 Jul 2014) New Revision: 47006 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47006 Log: get rid of function calls in RSTRING_PTR * process.c (rlimit_resource_type, rlimit_resource_value): get rid of function calls in RSTRING_PTR(), as it evaluates the argument twice. * re.c (match_backref_number): ditto. * signal.c (esignal_init, rb_f_kill, trap_signm): ditto. Modified files: trunk/process.c trunk/re.c trunk/signal.c Index: re.c =================================================================== --- re.c (revision 47005) +++ re.c (revision 47006) @@ -1082,8 +1082,8 @@ match_backref_number(VALUE match, VALUE https://github.com/ruby/ruby/blob/trunk/re.c#L1082 return NUM2INT(backref); case T_SYMBOL: - name = RSTRING_PTR(rb_sym2str(backref)); - break; + backref = rb_sym2str(backref); + /* fall through */ case T_STRING: name = StringValueCStr(backref); Index: process.c =================================================================== --- process.c (revision 47005) +++ process.c (revision 47006) @@ -4529,7 +4529,8 @@ rlimit_resource_type(VALUE rtype) https://github.com/ruby/ruby/blob/trunk/process.c#L4529 switch (TYPE(rtype)) { case T_SYMBOL: - name = RSTRING_PTR(rb_sym2str(rtype)); + v = rb_sym2str(rtype); + name = RSTRING_PTR(v); break; default: @@ -4564,7 +4565,8 @@ rlimit_resource_value(VALUE rval) https://github.com/ruby/ruby/blob/trunk/process.c#L4565 switch (TYPE(rval)) { case T_SYMBOL: - name = RSTRING_PTR(rb_sym2str(rval)); + v = rb_sym2str(rval); + name = RSTRING_PTR(v); break; default: Index: signal.c =================================================================== --- signal.c (revision 47005) +++ signal.c (revision 47006) @@ -301,7 +301,8 @@ esignal_init(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/signal.c#L301 } else { int len = sizeof(signame_prefix); - signm = SYMBOL_P(sig) ? RSTRING_PTR(rb_sym2str(sig)) : StringValuePtr(sig); + if (SYMBOL_P(sig)) sig = rb_sym2str(sig); else StringValue(sig); + signm = RSTRING_PTR(sig); if (strncmp(signm, signame_prefix, len) == 0) { signm += len; len = 0; @@ -408,7 +409,8 @@ rb_f_kill(int argc, const VALUE *argv) https://github.com/ruby/ruby/blob/trunk/signal.c#L409 break; case T_SYMBOL: - s = RSTRING_PTR(rb_sym2str(argv[0])); + str = rb_sym2str(argv[0]); + s = RSTRING_PTR(str); if (!s) rb_raise(rb_eArgError, "bad signal"); goto str_signal; @@ -1044,7 +1046,8 @@ trap_signm(VALUE vsig) https://github.com/ruby/ruby/blob/trunk/signal.c#L1046 break; case T_SYMBOL: - s = RSTRING_PTR(rb_sym2str(vsig)); + vsig = rb_sym2str(vsig); + s = RSTRING_PTR(vsig); if (!s) rb_raise(rb_eArgError, "bad signal"); goto str_signal; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/