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.
This commit is contained in:
parent
841eea4bcb
commit
19f2cabed8
Notes:
git
2020-06-29 11:06:47 +09:00
17
string.c
17
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user