summaryrefslogtreecommitdiff
path: root/insns.def
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 /insns.def
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 'insns.def')
-rw-r--r--insns.def29
1 files changed, 21 insertions, 8 deletions
diff --git a/insns.def b/insns.def
index fcd97ae613..6db675214a 100644
--- a/insns.def
+++ b/insns.def
@@ -1260,16 +1260,28 @@ opt_case_dispatch
(..., VALUE key)
() // inc += -1;
{
- if (BASIC_OP_UNREDEFINED_P(BOP_EQQ)) {
- VALUE val;
- if (st_lookup(RHASH_TBL(hash), key, &val)) {
- JUMP(FIX2INT(val));
+ switch(TYPE(key)) {
+ case T_FLOAT: {
+ double ival;
+ if (modf(RFLOAT_VALUE(key), &ival) == 0.0) {
+ key = FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
}
- else {
- JUMP(else_offset);
+ }
+ case T_SYMBOL: /* fall through */
+ case T_FIXNUM:
+ case T_BIGNUM:
+ case T_STRING:
+ if (BASIC_OP_UNREDEFINED_P(BOP_EQQ)) {
+ VALUE val;
+ if (st_lookup(RHASH_TBL(hash), key, &val)) {
+ JUMP(FIX2INT(val));
+ }
+ else {
+ JUMP(else_offset);
+ }
+ break;
}
- }
- else {
+ default: { /* fall through (else) */
struct opt_case_dispatch_i_arg arg;
arg.obj = key;
@@ -1282,6 +1294,7 @@ opt_case_dispatch
else {
JUMP(else_offset);
}
+ }
}
}