diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-06 11:14:05 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-06 11:14:05 +0000 |
commit | 42fe57d41b6a317d31f817f75e04851281e27750 (patch) | |
tree | 148c82adfc714aaa2a3d60cda2c18c4f78ed9f76 /internal.h | |
parent | c24d87191f249ef8fdd363226dce2fd67475079c (diff) | |
download | ruby-42fe57d41b6a317d31f817f75e04851281e27750.tar.gz |
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
Diffstat (limited to 'internal.h')
-rw-r--r-- | internal.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal.h b/internal.h index 06455f9409..bf54c64be7 100644 --- a/internal.h +++ b/internal.h @@ -1383,6 +1383,18 @@ rb_float_new_inline(double d) #define rb_float_value(v) rb_float_value_inline(v) #define rb_float_new(d) rb_float_new_inline(d) +static inline VALUE +rb_dbl2ival(double d) +{ + VALUE val; + if (rb_long2fix_overflow(d, &val)) { + return rb_dbl2big(d); + } + else { + return val; + } +} + /* object.c */ void rb_obj_copy_ivar(VALUE dest, VALUE obj); CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2)); |