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

ruby-changes:42091

From: mrkn <ko1@a...>
Date: Fri, 18 Mar 2016 02:15:39 +0900 (JST)
Subject: [ruby-changes:42091] mrkn:r54165 (trunk): * numeric.c (int_even_p): treat Fixnum and Bignum values directly.

mrkn	2016-03-18 02:15:33 +0900 (Fri, 18 Mar 2016)

  New Revision: 54165

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

  Log:
    * numeric.c (int_even_p): treat Fixnum and Bignum values directly.
    
    I forgot include this commit in the previous one.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 54164)
+++ numeric.c	(revision 54165)
@@ -2702,7 +2702,15 @@ int_odd_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2702
 static VALUE
 int_even_p(VALUE num)
 {
-    if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) {
+    if (FIXNUM_P(num)) {
+	if ((num & 2) == 0) {
+	    return Qtrue;
+	}
+    }
+    else if (RB_TYPE_P(num, T_BIGNUM)) {
+	return rb_big_even_p(num);
+    }
+    else if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) {
 	return Qtrue;
     }
     return Qfalse;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54164)
+++ ChangeLog	(revision 54165)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Mar 18 02:15:00 2016  Kenta Murata  <mrkn@m...>
+
+	* numeric.c (int_even_p): treat Fixnum and Bignum values directly.
+
 Fri Mar 18 02:07:00 2016  Kenta Murata  <mrkn@m...>
 
 	* bignum.c (Bignum#even?, Bignum#odd?): remove definitions
@@ -7,7 +11,7 @@ Fri Mar 18 02:07:00 2016  Kenta Murata https://github.com/ruby/ruby/blob/trunk/ChangeLog#L11
 	  definitions because they are unified with Numeric#zero?,
 	  Integer#even?, and Integer#odd?.
 
-	* numeric.c (num_zero_p, int_even_p, int_odd_p): treat Fixnum and
+	* numeric.c (num_zero_p, int_odd_p): treat Fixnum and
 	  Bignum values directly.
 
 	* test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless

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

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