mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* insns.def (opt_mod): Use % operator if both operands are positive for
a significant performance improvement. Thanks to @samsaffron. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e9b63c1a22
commit
4f683e1678
2 changed files with 11 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Apr 22 22:54:00 2013 Charlie Somerville <charlie@charliesomerville.com>
|
||||||
|
|
||||||
|
* insns.def (opt_mod): Use % operator if both operands are positive for
|
||||||
|
a significant performance improvement. Thanks to @samsaffron.
|
||||||
|
|
||||||
Mon Apr 22 17:09:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Apr 22 17:09:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* marshal.c (r_object0): copy all instance variables not only generic
|
* marshal.c (r_object0): copy all instance variables not only generic
|
||||||
|
|
10
insns.def
10
insns.def
|
@ -1524,13 +1524,15 @@ opt_mod
|
||||||
{
|
{
|
||||||
if (FIXNUM_2_P(recv, obj) &&
|
if (FIXNUM_2_P(recv, obj) &&
|
||||||
BASIC_OP_UNREDEFINED_P(BOP_MOD, FIXNUM_REDEFINED_OP_FLAG )) {
|
BASIC_OP_UNREDEFINED_P(BOP_MOD, FIXNUM_REDEFINED_OP_FLAG )) {
|
||||||
long x, y, mod;
|
long x, y;
|
||||||
|
|
||||||
x = FIX2LONG(recv);
|
x = FIX2LONG(recv);
|
||||||
y = FIX2LONG(obj);
|
y = FIX2LONG(obj);
|
||||||
{
|
if (x > 0 && y > 0) {
|
||||||
|
val = LONG2FIX(x % y);
|
||||||
|
} else {
|
||||||
/* copied from numeric.c#fixdivmod */
|
/* copied from numeric.c#fixdivmod */
|
||||||
long div;
|
long div, mod;
|
||||||
|
|
||||||
if (y == 0)
|
if (y == 0)
|
||||||
rb_num_zerodiv();
|
rb_num_zerodiv();
|
||||||
|
@ -1551,9 +1553,9 @@ opt_mod
|
||||||
mod += y;
|
mod += y;
|
||||||
div -= 1;
|
div -= 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
val = LONG2FIX(mod);
|
val = LONG2FIX(mod);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (FLONUM_2_P(recv, obj) &&
|
else if (FLONUM_2_P(recv, obj) &&
|
||||||
BASIC_OP_UNREDEFINED_P(BOP_MOD, FLOAT_REDEFINED_OP_FLAG)) {
|
BASIC_OP_UNREDEFINED_P(BOP_MOD, FLOAT_REDEFINED_OP_FLAG)) {
|
||||||
val = DBL2NUM(ruby_float_mod(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj)));
|
val = DBL2NUM(ruby_float_mod(RFLOAT_VALUE(recv), RFLOAT_VALUE(obj)));
|
||||||
|
|
Loading…
Add table
Reference in a new issue