ary_join_1: 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
4dc83eefce
commit
73f98d25eb
Notes:
git
2020-06-29 11:07:17 +09:00
73
array.c
73
array.c
@ -2943,6 +2943,34 @@ ary_join_0(VALUE ary, VALUE sep, long max, VALUE result)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ary_join_1_str(VALUE dst, VALUE src, int *first)
|
||||||
|
{
|
||||||
|
rb_str_buf_append(dst, src);
|
||||||
|
if (*first) {
|
||||||
|
rb_enc_copy(dst, src);
|
||||||
|
*first = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ary_join_1_ary(VALUE obj, VALUE ary, VALUE sep, VALUE result, VALUE val, int *first)
|
||||||
|
{
|
||||||
|
if (val == ary) {
|
||||||
|
rb_raise(rb_eArgError, "recursive array join");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
VALUE args[4];
|
||||||
|
|
||||||
|
*first = FALSE;
|
||||||
|
args[0] = val;
|
||||||
|
args[1] = sep;
|
||||||
|
args[2] = result;
|
||||||
|
args[3] = (VALUE)first;
|
||||||
|
rb_exec_recursive(recursive_join, obj, (VALUE)args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result, int *first)
|
ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result, int *first)
|
||||||
{
|
{
|
||||||
@ -2954,44 +2982,19 @@ ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result, int *first)
|
|||||||
|
|
||||||
val = RARRAY_AREF(ary, i);
|
val = RARRAY_AREF(ary, i);
|
||||||
if (RB_TYPE_P(val, T_STRING)) {
|
if (RB_TYPE_P(val, T_STRING)) {
|
||||||
str_join:
|
ary_join_1_str(result, val, first);
|
||||||
rb_str_buf_append(result, val);
|
|
||||||
if (*first) {
|
|
||||||
rb_enc_copy(result, val);
|
|
||||||
*first = FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (RB_TYPE_P(val, T_ARRAY)) {
|
else if (RB_TYPE_P(val, T_ARRAY)) {
|
||||||
obj = val;
|
ary_join_1_ary(val, ary, sep, result, val, first);
|
||||||
ary_join:
|
|
||||||
if (val == ary) {
|
|
||||||
rb_raise(rb_eArgError, "recursive array join");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
VALUE args[4];
|
|
||||||
|
|
||||||
*first = FALSE;
|
|
||||||
args[0] = val;
|
|
||||||
args[1] = sep;
|
|
||||||
args[2] = result;
|
|
||||||
args[3] = (VALUE)first;
|
|
||||||
rb_exec_recursive(recursive_join, obj, (VALUE)args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else if (!NIL_P(tmp = rb_check_string_type(val))) {
|
||||||
tmp = rb_check_string_type(val);
|
ary_join_1_str(result, tmp, first);
|
||||||
if (!NIL_P(tmp)) {
|
}
|
||||||
val = tmp;
|
else if (!NIL_P(tmp = rb_check_array_type(val))) {
|
||||||
goto str_join;
|
ary_join_1_ary(val, ary, sep, result, tmp, first);
|
||||||
}
|
}
|
||||||
tmp = rb_check_array_type(val);
|
else {
|
||||||
if (!NIL_P(tmp)) {
|
ary_join_1_str(result, rb_obj_as_string(val), first);
|
||||||
obj = val;
|
|
||||||
val = tmp;
|
|
||||||
goto ary_join;
|
|
||||||
}
|
|
||||||
val = rb_obj_as_string(val);
|
|
||||||
goto str_join;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user