ruby-changes:47867
From: nobu <ko1@a...>
Date: Fri, 22 Sep 2017 13:56:30 +0900 (JST)
Subject: [ruby-changes:47867] nobu:r59988 (trunk): numeric.c: reduced repeated calls
nobu 2017-09-22 13:56:24 +0900 (Fri, 22 Sep 2017) New Revision: 59988 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59988 Log: numeric.c: reduced repeated calls * numeric.c (rb_num2ll, rb_num2ull, fix_pow): turn repeated RFLOAT_VALUE calls into local variables. Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 59987) +++ numeric.c (revision 59988) @@ -3065,9 +3065,9 @@ rb_num2ll(VALUE val) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3065 if (FIXNUM_P(val)) return (LONG_LONG)FIX2LONG(val); else if (RB_TYPE_P(val, T_FLOAT)) { - if (RFLOAT_VALUE(val) < LLONG_MAX_PLUS_ONE - && (LLONG_MIN_MINUS_ONE_IS_LESS_THAN(RFLOAT_VALUE(val)))) { - return (LONG_LONG)(RFLOAT_VALUE(val)); + double d = RFLOAT_VALUE(val); + if (d < LLONG_MAX_PLUS_ONE && (LLONG_MIN_MINUS_ONE_IS_LESS_THAN(d))) { + return (LONG_LONG)d; } else { FLOAT_OUT_OF_RANGE(val, "long long"); @@ -3097,11 +3097,11 @@ rb_num2ull(VALUE val) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3097 return (LONG_LONG)FIX2LONG(val); /* this is FIX2LONG, intended */ } else if (RB_TYPE_P(val, T_FLOAT)) { - if (RFLOAT_VALUE(val) < ULLONG_MAX_PLUS_ONE - && LLONG_MIN_MINUS_ONE_IS_LESS_THAN(RFLOAT_VALUE(val))) { - if (0 <= RFLOAT_VALUE(val)) - return (unsigned LONG_LONG)(RFLOAT_VALUE(val)); - return (unsigned LONG_LONG)(LONG_LONG)(RFLOAT_VALUE(val)); + double d = RFLOAT_VALUE(val); + if (d < ULLONG_MAX_PLUS_ONE && LLONG_MIN_MINUS_ONE_IS_LESS_THAN(d)) { + if (0 <= d) + return (unsigned LONG_LONG)d; + return (unsigned LONG_LONG)(LONG_LONG)d; } else { FLOAT_OUT_OF_RANGE(val, "unsigned long long"); @@ -3983,13 +3983,13 @@ fix_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3983 return rb_big_pow(x, y); } else if (RB_TYPE_P(y, T_FLOAT)) { - if (RFLOAT_VALUE(y) == 0.0) return DBL2NUM(1.0); + double dy = RFLOAT_VALUE(y); + if (dy == 0.0) return DBL2NUM(1.0); if (a == 0) { - return DBL2NUM(RFLOAT_VALUE(y) < 0 ? INFINITY : 0.0); + return DBL2NUM(dy < 0 ? INFINITY : 0.0); } if (a == 1) return DBL2NUM(1.0); { - double dy = RFLOAT_VALUE(y); if (a < 0 && dy != round(dy)) return num_funcall1(rb_complex_raw1(x), idPow, y); return DBL2NUM(pow((double)a, dy)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/