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

ruby-changes:7243

From: akr <ko1@a...>
Date: Fri, 22 Aug 2008 03:51:16 +0900 (JST)
Subject: [ruby-changes:7243] Ruby:r18762 (trunk): * include/ruby/ruby.h (NUM2LONG): make it inline function to evaluete

akr	2008-08-22 03:49:13 +0900 (Fri, 22 Aug 2008)

  New Revision: 18762

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18762

  Log:
    * include/ruby/ruby.h (NUM2LONG): make it inline function to evaluete
      the argument only once.
      `t = Object.new; def t.*(x) p x; 0 end; p Time.at(0, t)' did print x
      twice.
      (NUM2INT): ditto.
      (NUM2LL): ditto.
      (INT2NUM): make it inline function.
      (LONG2NUM): ditto.
      (UINT2NUM): ditto.
      (ULONG2NUM): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/ruby.h

Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 18761)
+++ include/ruby/ruby.h	(revision 18762)
@@ -185,12 +185,10 @@
 #define LONG2FIX(i) INT2FIX(i)
 #define rb_fix_new(v) INT2FIX(v)
 VALUE rb_int2inum(SIGNED_VALUE);
-#define INT2NUM(v) rb_int2inum(v)
-#define LONG2NUM(v) INT2NUM(v)
+
 #define rb_int_new(v) rb_int2inum(v)
 VALUE rb_uint2inum(VALUE);
-#define UINT2NUM(v) rb_uint2inum(v)
-#define ULONG2NUM(v) UINT2NUM(v)
+
 #define rb_uint_new(v) rb_uint2inum(v)
 
 #ifdef HAVE_LONG_LONG
@@ -397,11 +395,19 @@
 
 SIGNED_VALUE rb_num2long(VALUE);
 VALUE rb_num2ulong(VALUE);
-#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x))
+static inline long
+NUM2LONG(VALUE x)
+{
+    return FIXNUM_P(x) ? FIX2LONG(x) : rb_num2long(x);
+}
 #define NUM2ULONG(x) rb_num2ulong((VALUE)x)
 #if SIZEOF_INT < SIZEOF_LONG
 long rb_num2int(VALUE);
-#define NUM2INT(x) ((int)(FIXNUM_P(x)?FIX2INT(x):rb_num2int((VALUE)x)))
+static inline int
+NUM2INT(VALUE x)
+{
+    return FIXNUM_P(x) ? FIX2INT(x) : rb_num2int(x);
+}
 long rb_fix2int(VALUE);
 #define FIX2INT(x) ((int)rb_fix2int((VALUE)x))
 unsigned long rb_num2uint(VALUE);
@@ -418,7 +424,11 @@
 #ifdef HAVE_LONG_LONG
 LONG_LONG rb_num2ll(VALUE);
 unsigned LONG_LONG rb_num2ull(VALUE);
-# define NUM2LL(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2ll((VALUE)x))
+static inline LONG_LONG
+NUM2LL(VALUE x)
+{
+    return FIXNUM_P(x) ? FIX2LONG(x) : rb_num2ll(x);
+}
 # define NUM2ULL(x) rb_num2ull((VALUE)x)
 #endif
 
@@ -439,6 +449,33 @@
 double rb_num2dbl(VALUE);
 #define NUM2DBL(x) rb_num2dbl((VALUE)(x))
 
+VALUE rb_uint2big(VALUE);
+VALUE rb_int2big(SIGNED_VALUE);
+static inline VALUE
+INT2NUM(int v)
+{
+    if (FIXABLE(v)) return INT2FIX(v);
+    return rb_int2big(v);
+}
+static inline VALUE
+LONG2NUM(long v)
+{
+    if (FIXABLE(v)) return LONG2FIX(v);
+    return rb_int2big(v);
+}
+static inline VALUE
+UINT2NUM(unsigned int v)
+{
+    if (POSFIXABLE(v)) return LONG2FIX(v);
+    return rb_uint2big(v);
+}
+static inline VALUE
+ULONG2NUM(unsigned long v)
+{
+    if (POSFIXABLE(v)) return LONG2FIX(v);
+    return rb_uint2big(v);
+}
+
 /* obsolete API - use StringValue() */
 char *rb_str2cstr(VALUE,long*);
 /* obsolete API - use StringValuePtr() */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18761)
+++ ChangeLog	(revision 18762)
@@ -1,3 +1,16 @@
+Fri Aug 22 03:19:41 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/ruby.h (NUM2LONG): make it inline function to evaluete
+	  the argument only once.
+	  `t = Object.new; def t.*(x) p x; 0 end; p Time.at(0, t)' did print x
+	  twice.
+	  (NUM2INT): ditto.
+	  (NUM2LL): ditto.
+	  (INT2NUM): make it inline function.
+	  (LONG2NUM): ditto.
+	  (UINT2NUM): ditto.
+	  (ULONG2NUM): ditto.
+
 Fri Aug 22 03:03:22 2008  Tanaka Akira  <akr@f...>
 
 	* io.c (rb_io_s_sysopen): mode can be a Bignum.

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

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