int_pow: 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
bf19820bb3
commit
250189f54f
Notes:
git
2020-06-29 11:06:59 +09:00
16
numeric.c
16
numeric.c
@ -3978,13 +3978,7 @@ int_pow(long x, unsigned long y)
|
|||||||
do {
|
do {
|
||||||
while (y % 2 == 0) {
|
while (y % 2 == 0) {
|
||||||
if (!FIT_SQRT_LONG(x)) {
|
if (!FIT_SQRT_LONG(x)) {
|
||||||
VALUE v;
|
goto bignum;
|
||||||
bignum:
|
|
||||||
v = rb_big_pow(rb_int2big(x), LONG2NUM(y));
|
|
||||||
if (RB_FLOAT_TYPE_P(v)) /* infinity due to overflow */
|
|
||||||
return v;
|
|
||||||
if (z != 1) v = rb_big_mul(rb_int2big(neg ? -z : z), v);
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
x = x * x;
|
x = x * x;
|
||||||
y >>= 1;
|
y >>= 1;
|
||||||
@ -3998,6 +3992,14 @@ int_pow(long x, unsigned long y)
|
|||||||
} while (--y);
|
} while (--y);
|
||||||
if (neg) z = -z;
|
if (neg) z = -z;
|
||||||
return LONG2NUM(z);
|
return LONG2NUM(z);
|
||||||
|
|
||||||
|
VALUE v;
|
||||||
|
bignum:
|
||||||
|
v = rb_big_pow(rb_int2big(x), LONG2NUM(y));
|
||||||
|
if (RB_FLOAT_TYPE_P(v)) /* infinity due to overflow */
|
||||||
|
return v;
|
||||||
|
if (z != 1) v = rb_big_mul(rb_int2big(neg ? -z : z), v);
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user