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

ruby-changes:45197

From: nobu <ko1@a...>
Date: Thu, 5 Jan 2017 16:27:24 +0900 (JST)
Subject: [ruby-changes:45197] nobu:r57270 (trunk): numeric.c: short circuit

nobu	2017-01-05 16:27:19 +0900 (Thu, 05 Jan 2017)

  New Revision: 57270

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57270

  Log:
    numeric.c: short circuit
    
    * numeric.c (int_pow): short circuit when y is 0, always return 1.

  Modified files:
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 57269)
+++ numeric.c	(revision 57270)
@@ -3892,6 +3892,7 @@ int_pow(long x, unsigned long y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3892
     int neg = x < 0;
     long z = 1;
 
+    if (y == 0) return INT2FIX(1);
     if (neg) x = -x;
     if (y & 1)
 	z = x;

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

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