summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-17 16:02:18 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commitc422fc4bbcb58a16fc84a287baa3cb2d454d7a81 (patch)
tree0ef0264ae52ab6127bb3f80886c14fa177980c1f /string.c
parentc29ec1ef1a88626319c39db02e7574c13f9b72d3 (diff)
rb_str_rindex_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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'string.c')
-rw-r--r--string.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/string.c b/string.c
index 7470213040..2abb8296b3 100644
--- a/string.c
+++ b/string.c
@@ -3821,9 +3821,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
pos = len;
}
- if (SPECIAL_CONST_P(sub)) goto generic;
- switch (BUILTIN_TYPE(sub)) {
- case T_REGEXP:
+ if (RB_TYPE_P(sub, T_REGEXP)) {
/* enc = rb_get_check(str, sub); */
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
enc, single_byte_optimizable(str));
@@ -3831,24 +3829,11 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
pos = rb_reg_search(sub, str, pos, 1);
pos = rb_str_sublen(str, pos);
if (pos >= 0) return LONG2NUM(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_rindex(str, sub, pos);
if (pos >= 0) return LONG2NUM(pos);
- break;
}
return Qnil;
}