mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
signm2signo: 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
7cf4625690
commit
224e9c3835
Notes:
git
2020-06-29 11:06:51 +09:00
1 changed files with 19 additions and 18 deletions
37
signal.c
37
signal.c
|
@ -243,23 +243,7 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
|
||||||
prefix += signame_prefix_len;
|
prefix += signame_prefix_len;
|
||||||
}
|
}
|
||||||
if (len <= (long)prefix) {
|
if (len <= (long)prefix) {
|
||||||
unsupported:
|
goto unsupported;
|
||||||
if (prefix == signame_prefix_len) {
|
|
||||||
prefix = 0;
|
|
||||||
}
|
|
||||||
else if (prefix > signame_prefix_len) {
|
|
||||||
prefix -= signame_prefix_len;
|
|
||||||
len -= prefix;
|
|
||||||
vsig = rb_str_subseq(vsig, prefix, len);
|
|
||||||
prefix = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
len -= prefix;
|
|
||||||
vsig = rb_str_subseq(vsig, prefix, len);
|
|
||||||
prefix = signame_prefix_len;
|
|
||||||
}
|
|
||||||
rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'",
|
|
||||||
prefix, signame_prefix, vsig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix_ptr) *prefix_ptr = prefix;
|
if (prefix_ptr) *prefix_ptr = prefix;
|
||||||
|
@ -272,7 +256,24 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
|
||||||
return negative ? -sigs->signo : sigs->signo;
|
return negative ? -sigs->signo : sigs->signo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto unsupported;
|
|
||||||
|
unsupported:
|
||||||
|
if (prefix == signame_prefix_len) {
|
||||||
|
prefix = 0;
|
||||||
|
}
|
||||||
|
else if (prefix > signame_prefix_len) {
|
||||||
|
prefix -= signame_prefix_len;
|
||||||
|
len -= prefix;
|
||||||
|
vsig = rb_str_subseq(vsig, prefix, len);
|
||||||
|
prefix = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
len -= prefix;
|
||||||
|
vsig = rb_str_subseq(vsig, prefix, len);
|
||||||
|
prefix = signame_prefix_len;
|
||||||
|
}
|
||||||
|
rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'",
|
||||||
|
prefix, signame_prefix, vsig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char*
|
static const char*
|
||||||
|
|
Loading…
Reference in a new issue