ruby-changes:62019
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:07:34 +0900 (JST)
Subject: [ruby-changes:62019] c29ec1ef1a (master): rb_str_index_m: do not goto into a branch
https://git.ruby-lang.org/ruby.git/commit/?id=c29ec1ef1a From c29ec1ef1a88626319c39db02e7574c13f9b72d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Wed, 17 Jun 2020 15:31:10 +0900 Subject: rb_str_index_m: do not goto into a branch I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. diff --git a/string.c b/string.c index c9c65a4..7470213 100644 --- a/string.c +++ b/string.c @@ -3669,9 +3669,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L3669 } } - if (SPECIAL_CONST_P(sub)) goto generic; - switch (BUILTIN_TYPE(sub)) { - case T_REGEXP: + if (RB_TYPE_P(sub, T_REGEXP)) { if (pos > str_strlen(str, NULL)) return Qnil; pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos, @@ -3679,24 +3677,11 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L3677 pos = rb_reg_search(sub, str, pos, 0); pos = rb_str_sublen(str, pos); - break; - - generic: - default: { - VALUE tmp; - - tmp = rb_check_string_type(sub); - if (NIL_P(tmp)) { - rb_raise(rb_eTypeError, "type mismatch: %s given", - rb_obj_classname(sub)); - } - sub = tmp; - } - /* fall through */ - case T_STRING: + } + else { + StringValue(sub); pos = rb_str_index(str, sub, pos); pos = rb_str_sublen(str, pos); - break; } if (pos == -1) return Qnil; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/