summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorwanabe <wanabe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-09 13:40:14 +0000
committerwanabe <wanabe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-09 13:40:14 +0000
commit96688ecbab2e18be02af7172bcb3732e57d9290e (patch)
treea4f5761850518bd0a89e98d4e0fb681906f8cff9 /compile.c
parente54c30c05eb16897bc1d44b3bec06083ef1ae779 (diff)
* compile.c (case_when_optimizable_literal): When float value can be
treated as integer, add to table hash of case that way. based on a patch from Ikuo KOBORI. [ruby-dev:42038] * insnf.def (opt_case_dispatch): ditto. * test/ruby/test_case.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index 2fd804cac4..8cbf253cf2 100644
--- a/compile.c
+++ b/compile.c
@@ -2303,6 +2303,11 @@ case_when_optimizable_literal(NODE * node)
switch (nd_type(node)) {
case NODE_LIT: {
VALUE v = node->nd_lit;
+ double ival;
+ if (TYPE(v) == T_FLOAT &&
+ modf(RFLOAT_VALUE(v), &ival) == 0.0) {
+ return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
+ }
if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) {
return v;
}