From 19f2cabed88943f8adae00c9588e47f7e9112a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Thu, 18 Jun 2020 13:41:34 +0900 Subject: [PATCH] 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. --- string.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/string.c b/string.c index f4bcfba6d0..4bfd9f5a7e 100644 --- a/string.c +++ b/string.c @@ -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; } }