ruby-changes:42221
From: nobu <ko1@a...>
Date: Sat, 26 Mar 2016 10:52:05 +0900 (JST)
Subject: [ruby-changes:42221] nobu:r54295 (trunk): numeric.c: Fixnum predicts
nobu 2016-03-26 10:52:00 +0900 (Sat, 26 Mar 2016) New Revision: 54295 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54295 Log: numeric.c: Fixnum predicts * numeric.c (FIXNUM_{POSITIVE,NEGATIVE,ZERO}_P): predict macros only for Fixnum. Modified files: trunk/ChangeLog trunk/numeric.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54294) +++ ChangeLog (revision 54295) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Mar 26 10:51:58 2016 Nobuyoshi Nakada <nobu@r...> + + * numeric.c (FIXNUM_{POSITIVE,NEGATIVE,ZERO}_P): predict macros + only for Fixnum. + Sat Mar 26 06:34:24 2016 NARUSE, Yui <naruse@r...> * localeinit.c (rb_locale_charmap_index): fix prototype. Index: numeric.c =================================================================== --- numeric.c (revision 54294) +++ numeric.c (revision 54295) @@ -173,6 +173,10 @@ compare_with_zero(VALUE num, ID mid) https://github.com/ruby/ruby/blob/trunk/numeric.c#L173 return r; } +#define FIXNUM_POSITIVE_P(num) ((SIGNED_VALUE)(num) > (SIGNED_VALUE)INT2FIX(0)) +#define FIXNUM_NEGATIVE_P(num) ((SIGNED_VALUE)(num) < 0) +#define FIXNUM_ZERO_P(num) ((num) == INT2FIX(0)) + static inline int positive_int_p(VALUE num) { @@ -180,7 +184,7 @@ positive_int_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L184 if (FIXNUM_P(num)) { if (method_basic_p(rb_cFixnum)) - return (SIGNED_VALUE)num > 0; + return FIXNUM_POSITIVE_P(num); } else if (RB_TYPE_P(num, T_BIGNUM)) { if (method_basic_p(rb_cBignum)) @@ -196,7 +200,7 @@ negative_int_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L200 if (FIXNUM_P(num)) { if (method_basic_p(rb_cFixnum)) - return (SIGNED_VALUE)num < 0; + return FIXNUM_NEGATIVE_P(num); } else if (RB_TYPE_P(num, T_BIGNUM)) { if (method_basic_p(rb_cBignum)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/