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 --- object.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 9ec96687e9..21779401fb 100644 --- a/object.c +++ b/object.c @@ -2747,11 +2747,8 @@ rb_convert_to_integer(VALUE val, int base) VALUE tmp; if (RB_FLOAT_TYPE_P(val)) { - double f; if (base != 0) goto arg_error; - f = RFLOAT_VALUE(val); - if (FIXABLE(f)) return LONG2FIX((long)f); - return rb_dbl2big(f); + return rb_dbl2ival(RFLOAT_VALUE(val)); } else if (RB_INTEGER_TYPE_P(val)) { if (base != 0) goto arg_error; -- cgit v1.2.3