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

ruby-changes:42090

From: mrkn <ko1@a...>
Date: Fri, 18 Mar 2016 02:11:47 +0900 (JST)
Subject: [ruby-changes:42090] mrkn:r54164 (trunk): * bignum.c (Bignum#even?, Bignum#odd?): remove definitions

mrkn	2016-03-18 02:11:42 +0900 (Fri, 18 Mar 2016)

  New Revision: 54164

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

  Log:
    * bignum.c (Bignum#even?, Bignum#odd?): remove definitions
      because they are unified with Integer#even? and Integer#odd?.
    
    * numeric.c (Fixnum#zero?, Fixnum#even?, Fixnum#odd?): remove
      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
      Bignum values directly.
    
    * test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless
      test case.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/numeric.c
    trunk/test/ruby/test_integer.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54163)
+++ ChangeLog	(revision 54164)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Mar 18 02:07:00 2016  Kenta Murata  <mrkn@m...>
+
+	* bignum.c (Bignum#even?, Bignum#odd?): remove definitions
+	  because they are unified with Integer#even? and Integer#odd?.
+
+	* numeric.c (Fixnum#zero?, Fixnum#even?, Fixnum#odd?): remove
+	  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
+	  Bignum values directly.
+
+	* test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless
+	  test case.
+
 Fri Mar 18 01:51:00 2016  Kenta Murata  <mrkn@m...>
 
 	* bignum.c (rb_big_even_p, rb_big_odd_p): make them public functions
Index: bignum.c
===================================================================
--- bignum.c	(revision 54163)
+++ bignum.c	(revision 54164)
@@ -7091,8 +7091,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L7091
     rb_define_method(rb_cBignum, "magnitude", rb_big_abs, 0);
     rb_define_method(rb_cBignum, "size", rb_big_size, 0);
     rb_define_method(rb_cBignum, "bit_length", rb_big_bit_length, 0);
-    rb_define_method(rb_cBignum, "odd?", rb_big_odd_p, 0);
-    rb_define_method(rb_cBignum, "even?", rb_big_even_p, 0);
 
 #ifdef USE_GMP
     /* The version of loaded GMP. */
Index: test/ruby/test_integer.rb
===================================================================
--- test/ruby/test_integer.rb	(revision 54163)
+++ test/ruby/test_integer.rb	(revision 54164)
@@ -105,26 +105,6 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L105
     assert_predicate(1, :integer?)
   end
 
-  def test_odd_p_even_p
-    Fixnum.class_eval do
-      alias odd_bak odd?
-      alias even_bak even?
-      remove_method :odd?, :even?
-    end
-
-    assert_predicate(1, :odd?)
-    assert_not_predicate(2, :odd?)
-    assert_not_predicate(1, :even?)
-    assert_predicate(2, :even?)
-
-  ensure
-    Fixnum.class_eval do
-      alias odd? odd_bak
-      alias even? even_bak
-      remove_method :odd_bak, :even_bak
-    end
-  end
-
   def test_succ
     assert_equal(2, 1.send(:succ))
 
Index: numeric.c
===================================================================
--- numeric.c	(revision 54163)
+++ numeric.c	(revision 54164)
@@ -605,7 +605,15 @@ num_abs(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L605
 static VALUE
 num_zero_p(VALUE num)
 {
-    if (rb_equal(num, INT2FIX(0))) {
+    if (FIXNUM_P(num)) {
+	if (FIX2LONG(num) == 0) {
+	    return Qtrue;
+	}
+    }
+    else if (RB_TYPE_P(num, T_BIGNUM)) {
+	return rb_bigzero_p(num);
+    }
+    else if (rb_equal(num, INT2FIX(0))) {
 	return Qtrue;
     }
     return Qfalse;
@@ -2670,7 +2678,15 @@ int_int_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2678
 static VALUE
 int_odd_p(VALUE num)
 {
-    if (rb_funcall(num, '%', 1, INT2FIX(2)) != INT2FIX(0)) {
+    if (FIXNUM_P(num)) {
+	if (num & 2) {
+	    return Qtrue;
+	}
+    }
+    else if (RB_TYPE_P(num, T_BIGNUM)) {
+	return rb_big_odd_p(num);
+    }
+    else if (rb_funcall(num, '%', 1, INT2FIX(2)) != INT2FIX(0)) {
 	return Qtrue;
     }
     return Qfalse;
@@ -4268,9 +4284,6 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4284
     rb_define_method(rb_cFixnum, "to_f", fix_to_f, 0);
     rb_define_method(rb_cFixnum, "size", fix_size, 0);
     rb_define_method(rb_cFixnum, "bit_length", rb_fix_bit_length, 0);
-    rb_define_method(rb_cFixnum, "zero?", fix_zero_p, 0);
-    rb_define_method(rb_cFixnum, "odd?", fix_odd_p, 0);
-    rb_define_method(rb_cFixnum, "even?", fix_even_p, 0);
     rb_define_method(rb_cFixnum, "succ", fix_succ, 0);
 
     rb_cFloat  = rb_define_class("Float", rb_cNumeric);

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

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