[前][次][番号順一覧][スレッド一覧]

ruby-changes:62000

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:07:01 +0900 (JST)
Subject: [ruby-changes:62000] 250189f54f (master): int_pow: do not goto into a branch

https://git.ruby-lang.org/ruby.git/commit/?id=250189f54f

From 250189f54f2cf690195573ee82082c42b21ccac6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 16 Jun 2020 10:05:46 +0900
Subject: 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.

diff --git a/numeric.c b/numeric.c
index 8843be9..52d7a74 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3978,13 +3978,7 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3978
     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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3992
     } 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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]