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

ruby-changes:42706

From: akr <ko1@a...>
Date: Tue, 26 Apr 2016 19:50:39 +0900 (JST)
Subject: [ruby-changes:42706] akr:r54780 (trunk): {Fixnum, Bignum}#size is unified into Integer.

akr	2016-04-26 20:47:14 +0900 (Tue, 26 Apr 2016)

  New Revision: 54780

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

  Log:
    {Fixnum,Bignum}#size is unified into Integer.
    
    * numeric.c (int_size): {Fixnum,Bignum}#size is unified into Integer.
    
    * bignum.c (rb_big_size_m): Don't define Bignum#size.
    
    * internal.h (rb_big_size_m): Declared.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/internal.h
    trunk/numeric.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54779)
+++ ChangeLog	(revision 54780)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Apr 26 20:46:16 2016  Tanaka Akira  <akr@f...>
+
+	* numeric.c (int_size): {Fixnum,Bignum}#size is unified into Integer.
+
+	* bignum.c (rb_big_size_m): Don't define Bignum#size.
+
+	* internal.h (rb_big_size_m): Declared.
+
 Tue Apr 26 20:09:08 2016  Tanaka Akira  <akr@f...>
 
 	* numeric.c (rb_int_bit_length): {Fixnum,Bignum}#bit_length is
Index: internal.h
===================================================================
--- internal.h	(revision 54779)
+++ internal.h	(revision 54780)
@@ -779,6 +779,7 @@ VALUE rb_integer_float_cmp(VALUE x, VALU https://github.com/ruby/ruby/blob/trunk/internal.h#L779
 VALUE rb_integer_float_eq(VALUE x, VALUE y);
 VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base);
 VALUE rb_big_abs(VALUE x);
+VALUE rb_big_size_m(VALUE big);
 VALUE rb_big_bit_length(VALUE big);
 
 /* class.c */
Index: bignum.c
===================================================================
--- bignum.c	(revision 54779)
+++ bignum.c	(revision 54780)
@@ -6902,19 +6902,7 @@ rb_big_size(VALUE big) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6902
     return BIGSIZE(big);
 }
 
-/*
- *  call-seq:
- *     big.size -> integer
- *
- *  Returns the number of bytes in the machine representation of
- *  <i>big</i>.
- *
- *     (256**10 - 1).size   #=> 12
- *     (256**20 - 1).size   #=> 20
- *     (256**40 - 1).size   #=> 40
- */
-
-static VALUE
+VALUE
 rb_big_size_m(VALUE big)
 {
     return SIZET2NUM(rb_big_size(big));
@@ -7043,7 +7031,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L7031
     rb_define_method(rb_cBignum, "<", big_lt, 1);
     rb_define_method(rb_cBignum, "<=", big_le, 1);
     rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
-    rb_define_method(rb_cBignum, "size", rb_big_size_m, 0);
 
 #ifdef USE_GMP
     /* The version of loaded GMP. */
Index: numeric.c
===================================================================
--- numeric.c	(revision 54779)
+++ numeric.c	(revision 54780)
@@ -4104,21 +4104,36 @@ int_abs(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4104
     return Qnil;
 }
 
+static VALUE
+fix_size(VALUE fix)
+{
+    return INT2FIX(sizeof(long));
+}
+
 /*
  *  call-seq:
- *     fix.size  ->  fixnum
+ *     int.size  ->  int
  *
  *  Returns the number of bytes in the machine representation of +fix+.
  *
  *     1.size            #=> 4
  *     -1.size           #=> 4
  *     2147483647.size   #=> 4
+ *     (256**10 - 1).size   #=> 12
+ *     (256**20 - 1).size   #=> 20
+ *     (256**40 - 1).size   #=> 40
  */
 
 static VALUE
-fix_size(VALUE fix)
+int_size(VALUE num)
 {
-    return INT2FIX(sizeof(long));
+    if (FIXNUM_P(num)) {
+	return fix_size(num);
+    }
+    else if (RB_TYPE_P(num, T_BIGNUM)) {
+	return rb_big_size_m(num);
+    }
+    return Qnil;
 }
 
 static VALUE
@@ -4669,7 +4684,7 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4684
     rb_define_method(rb_cFixnum, "<<", rb_fix_lshift, 1);
     rb_define_method(rb_cFixnum, ">>", rb_fix_rshift, 1);
 
-    rb_define_method(rb_cFixnum, "size", fix_size, 0);
+    rb_define_method(rb_cInteger, "size", int_size, 0);
     rb_define_method(rb_cInteger, "bit_length", rb_int_bit_length, 0);
     rb_define_method(rb_cFixnum, "succ", fix_succ, 0);
 

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

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