diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-18 13:41:34 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | 19f2cabed88943f8adae00c9588e47f7e9112a9e (patch) | |
tree | 9e5a981b936646792f87797ad0b2afa0bfe3ff48 /string.c | |
parent | 841eea4bcbfe22d6d1a71381cd1e98ca6b6cfde7 (diff) |
rb_str_aset: 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.c | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -4796,15 +4796,7 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val) { long idx, beg; - if (FIXNUM_P(indx)) { - idx = FIX2LONG(indx); - num_index: - rb_str_splice(str, idx, 1, val); - return val; - } - - if (SPECIAL_CONST_P(indx)) goto generic; - switch (BUILTIN_TYPE(indx)) { + switch (TYPE(indx)) { case T_REGEXP: rb_str_subpat_set(str, indx, INT2FIX(0), val); return val; @@ -4818,7 +4810,6 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val) rb_str_splice(str, beg, str_strlen(indx, NULL), val); return val; - generic: default: /* check if indx is Range */ { @@ -4828,8 +4819,12 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val) return val; } } + /* FALLTHROUGH */ + + case T_FIXNUM: idx = NUM2LONG(indx); - goto num_index; + rb_str_splice(str, idx, 1, val); + return val; } } |