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

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-07-30 13:46:41 +00:00
parent 3b895e8355
commit e5a7c2db98
3 changed files with 12 additions and 7 deletions

View file

@ -4529,7 +4529,8 @@ rlimit_resource_type(VALUE rtype)
switch (TYPE(rtype)) { switch (TYPE(rtype)) {
case T_SYMBOL: case T_SYMBOL:
name = RSTRING_PTR(rb_sym2str(rtype)); v = rb_sym2str(rtype);
name = RSTRING_PTR(v);
break; break;
default: default:
@ -4564,7 +4565,8 @@ rlimit_resource_value(VALUE rval)
switch (TYPE(rval)) { switch (TYPE(rval)) {
case T_SYMBOL: case T_SYMBOL:
name = RSTRING_PTR(rb_sym2str(rval)); v = rb_sym2str(rval);
name = RSTRING_PTR(v);
break; break;
default: default:

4
re.c
View file

@ -1082,8 +1082,8 @@ match_backref_number(VALUE match, VALUE backref)
return NUM2INT(backref); return NUM2INT(backref);
case T_SYMBOL: case T_SYMBOL:
name = RSTRING_PTR(rb_sym2str(backref)); backref = rb_sym2str(backref);
break; /* fall through */
case T_STRING: case T_STRING:
name = StringValueCStr(backref); name = StringValueCStr(backref);

View file

@ -301,7 +301,8 @@ esignal_init(int argc, VALUE *argv, VALUE self)
} }
else { else {
int len = sizeof(signame_prefix); 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) { if (strncmp(signm, signame_prefix, len) == 0) {
signm += len; signm += len;
len = 0; len = 0;
@ -408,7 +409,8 @@ rb_f_kill(int argc, const VALUE *argv)
break; break;
case T_SYMBOL: 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"); if (!s) rb_raise(rb_eArgError, "bad signal");
goto str_signal; goto str_signal;
@ -1044,7 +1046,8 @@ trap_signm(VALUE vsig)
break; break;
case T_SYMBOL: 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"); if (!s) rb_raise(rb_eArgError, "bad signal");
goto str_signal; goto str_signal;