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

ruby-changes:54543

From: mrkn <ko1@a...>
Date: Wed, 9 Jan 2019 16:05:43 +0900 (JST)
Subject: [ruby-changes:54543] mrkn:r66758 (trunk): complex.c: optimize zero check for Float

mrkn	2019-01-09 16:05:37 +0900 (Wed, 09 Jan 2019)

  New Revision: 66758

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

  Log:
    complex.c: optimize zero check for Float

  Modified files:
    trunk/complex.c
    trunk/internal.h
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 66757)
+++ numeric.c	(revision 66758)
@@ -1086,7 +1086,7 @@ rb_float_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1086
 static bool
 flo_iszero(VALUE f)
 {
-    return RFLOAT_VALUE(f) == 0.0;
+    return FLOAT_ZERO_P(f);
 }
 
 static double
Index: internal.h
===================================================================
--- internal.h	(revision 66757)
+++ internal.h	(revision 66758)
@@ -1617,6 +1617,8 @@ void Init_newline(void); https://github.com/ruby/ruby/blob/trunk/internal.h#L1617
 
 #define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
 
+#define FLOAT_ZERO_P(x) (RFLOAT_VALUE(x) == 0.0)
+
 #ifndef ROUND_DEFAULT
 # define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
 #endif
Index: complex.c
===================================================================
--- complex.c	(revision 66757)
+++ complex.c	(revision 66758)
@@ -232,7 +232,10 @@ f_negative_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L232
 inline static int
 f_zero_p(VALUE x)
 {
-    if (RB_INTEGER_TYPE_P(x)) {
+    if (RB_FLOAT_TYPE_P(x)) {
+        return FLOAT_ZERO_P(x);
+    }
+    else if (RB_INTEGER_TYPE_P(x)) {
         return FIXNUM_ZERO_P(x);
     }
     else if (RB_TYPE_P(x, T_RATIONAL)) {

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

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