ruby-changes:51337
From: nobu <ko1@a...>
Date: Fri, 1 Jun 2018 15:53:33 +0900 (JST)
Subject: [ruby-changes:51337] nobu:r63543 (trunk): string.c: trivial optimizations
nobu 2018-06-01 15:53:26 +0900 (Fri, 01 Jun 2018) New Revision: 63543 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63543 Log: string.c: trivial optimizations * string.c (rb_str_aset): prefer BUILTIN_TYPE over TYPE after SPECIAL_CONST_P check. * string.c (rb_str_start_with): prefer RB_TYPE_P over switch by TYPE. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 63542) +++ string.c (revision 63543) @@ -4724,7 +4724,7 @@ rb_str_aset(VALUE str, VALUE indx, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L4724 } if (SPECIAL_CONST_P(indx)) goto generic; - switch (TYPE(indx)) { + switch (BUILTIN_TYPE(indx)) { case T_REGEXP: rb_str_subpat_set(str, indx, INT2FIX(0), val); return val; @@ -9628,14 +9628,11 @@ rb_str_start_with(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/string.c#L9628 for (i=0; i<argc; i++) { VALUE tmp = argv[i]; - switch (TYPE(tmp)) { - case T_REGEXP: - { - bool r = rb_reg_start_with_p(tmp, str); - if (r) return Qtrue; - } - break; - default: + if (RB_TYPE_P(tmp, T_REGEXP)) { + if (rb_reg_start_with_p(tmp, str)) + return Qtrue; + } + else { StringValue(tmp); rb_enc_check(str, tmp); if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/