summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-16 10:05:46 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit250189f54f2cf690195573ee82082c42b21ccac6 (patch)
treec91db83131966ed8c2df9354c3da0a739d5b1e26 /numeric.c
parentbf19820bb383cffd2b85cc0c2c6a6e72f5e5f471 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/numeric.c b/numeric.c
index 8843be9e58..52d7a74344 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3978,13 +3978,7 @@ int_pow(long x, unsigned long y)
do {
while (y % 2 == 0) {
if (!FIT_SQRT_LONG(x)) {
- 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;
+ goto bignum;
}
x = x * x;
y >>= 1;
@@ -3998,6 +3992,14 @@ int_pow(long x, unsigned long y)
} while (--y);
if (neg) z = -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