summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-18 16:55:52 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit5f926b2b0013fc196ba627e70b7961a71aabca11 (patch)
tree646aad5e0cc3f0d11972eb9bf6a3a7209260ca01
parente3d821a36ce9040542bb3fb8e1fa97df3fd06499 (diff)
rb_str_partition: 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
-rw-r--r--string.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/string.c b/string.c
index c74e8ebbb7..903222e0e4 100644
--- a/string.c
+++ b/string.c
@@ -9939,8 +9939,7 @@ rb_str_partition(VALUE str, VALUE sep)
if (RB_TYPE_P(sep, T_REGEXP)) {
pos = rb_reg_search(sep, str, 0, 0);
if (pos < 0) {
- failed:
- return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
+ goto failed;
}
sep = rb_str_subpat(str, sep, INT2FIX(0));
}
@@ -9952,6 +9951,9 @@ rb_str_partition(VALUE str, VALUE sep)
sep,
rb_str_subseq(str, pos+RSTRING_LEN(sep),
RSTRING_LEN(str)-pos-RSTRING_LEN(sep)));
+
+ failed:
+ return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
}
/*