ruby-changes:24099
From: nobu <ko1@a...>
Date: Wed, 20 Jun 2012 15:31:47 +0900 (JST)
Subject: [ruby-changes:24099] nobu:r36150 (trunk): numeric.c: optimize
nobu 2012-06-20 15:31:35 +0900 (Wed, 20 Jun 2012) New Revision: 36150 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36150 Log: numeric.c: optimize * numeric.c (positive_int_p, negative_int_p): optimize. Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 36149) +++ numeric.c (revision 36150) @@ -150,10 +150,21 @@ return NUMERR_TYPE; } +#define method_basic_p(klass) rb_method_basic_definition_p(klass, mid) + static inline int positive_int_p(VALUE num) { const ID mid = '>'; + + if (FIXNUM_P(num)) { + if (method_basic_p(rb_cFixnum)) + return (SIGNED_VALUE)num > 0; + } + else if (RB_TYPE_P(num, T_BIGNUM)) { + if (method_basic_p(rb_cBignum)) + return RBIGNUM_POSITIVE_P(num); + } return RTEST(rb_funcall(num, mid, 1, INT2FIX(0))); } @@ -161,6 +172,15 @@ negative_int_p(VALUE num) { const ID mid = '<'; + + if (FIXNUM_P(num)) { + if (method_basic_p(rb_cFixnum)) + return (SIGNED_VALUE)num < 0; + } + else if (RB_TYPE_P(num, T_BIGNUM)) { + if (method_basic_p(rb_cBignum)) + return RBIGNUM_NEGATIVE_P(num); + } return RTEST(rb_funcall(num, mid, 1, INT2FIX(0))); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/