From 74cdd893eb102ba98e735f2a24c710e1928261a9 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Mon, 6 Mar 2017 11:14:05 +0000 Subject: optimize FIXABLE macro Looking at the source code, FIXABLE tends to be just before LOING2FIX to check applicability of that operation. Why not try computing first then check for overflow, which should be optimial. I also tried the same thing for unsigned types but resulted in slower execution. It seems RB_POSFIXABLE() is fast enough on modern CPUs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sprintf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'sprintf.c') diff --git a/sprintf.c b/sprintf.c index 40872c0c16..72ac664e0e 100644 --- a/sprintf.c +++ b/sprintf.c @@ -832,11 +832,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) bin_retry: switch (TYPE(val)) { case T_FLOAT: - if (FIXABLE(RFLOAT_VALUE(val))) { - val = LONG2FIX((long)RFLOAT_VALUE(val)); - goto bin_retry; - } - val = rb_dbl2big(RFLOAT_VALUE(val)); + val = rb_dbl2ival(RFLOAT_VALUE(val)); if (FIXNUM_P(val)) goto bin_retry; bignum = 1; break; -- cgit v1.2.3