зеркало из https://github.com/github/ruby.git
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:
Родитель
f96afe182e
Коммит
50aab6d401
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)));
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче