mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
numeric.c: optimize
* numeric.c (positive_int_p, negative_int_p): optimize. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f96afe182e
commit
50aab6d401
1 changed files with 20 additions and 0 deletions
20
numeric.c
20
numeric.c
|
@ -150,10 +150,21 @@ rb_num_to_uint(VALUE val, unsigned int *ret)
|
|||
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 @@ static inline int
|
|||
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)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue