summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-06 11:14:05 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-06 11:14:05 +0000
commit74cdd893eb102ba98e735f2a24c710e1928261a9 (patch)
tree148c82adfc714aaa2a3d60cda2c18c4f78ed9f76 /sprintf.c
parentcf2a68662aadcbed4a92cfdad4d992f894f3767f (diff)
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 'sprintf.c')
-rw-r--r--sprintf.c6
1 files changed, 1 insertions, 5 deletions
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;