mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
e54c30c05e
commit
96688ecbab
4 changed files with 55 additions and 8 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Thu Sep 9 22:34:48 2010 wanabe <s.wanabe@gmail.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Thu Sep 9 17:15:15 2010 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
Thu Sep 9 17:15:15 2010 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* test/net/http/test_https.rb (test_identity_verify_failure): follows
|
* test/net/http/test_https.rb (test_identity_verify_failure): follows
|
||||||
|
|
|
@ -2303,6 +2303,11 @@ case_when_optimizable_literal(NODE * node)
|
||||||
switch (nd_type(node)) {
|
switch (nd_type(node)) {
|
||||||
case NODE_LIT: {
|
case NODE_LIT: {
|
||||||
VALUE v = node->nd_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)) {
|
if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
15
insns.def
15
insns.def
|
@ -1260,6 +1260,17 @@ opt_case_dispatch
|
||||||
(..., VALUE key)
|
(..., VALUE key)
|
||||||
() // inc += -1;
|
() // inc += -1;
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case T_SYMBOL: /* fall through */
|
||||||
|
case T_FIXNUM:
|
||||||
|
case T_BIGNUM:
|
||||||
|
case T_STRING:
|
||||||
if (BASIC_OP_UNREDEFINED_P(BOP_EQQ)) {
|
if (BASIC_OP_UNREDEFINED_P(BOP_EQQ)) {
|
||||||
VALUE val;
|
VALUE val;
|
||||||
if (st_lookup(RHASH_TBL(hash), key, &val)) {
|
if (st_lookup(RHASH_TBL(hash), key, &val)) {
|
||||||
|
@ -1268,8 +1279,9 @@ opt_case_dispatch
|
||||||
else {
|
else {
|
||||||
JUMP(else_offset);
|
JUMP(else_offset);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
default: { /* fall through (else) */
|
||||||
struct opt_case_dispatch_i_arg arg;
|
struct opt_case_dispatch_i_arg arg;
|
||||||
|
|
||||||
arg.obj = key;
|
arg.obj = key;
|
||||||
|
@ -1284,6 +1296,7 @@ opt_case_dispatch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@c optimize
|
@c optimize
|
||||||
|
|
|
@ -84,4 +84,23 @@ class TestCase < Test::Unit::TestCase
|
||||||
class Fixnum; undef ===; def ===(o); p 42; true; end; end; case 1; when 1; end
|
class Fixnum; undef ===; def ===(o); p 42; true; end; end; case 1; when 1; end
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_optimization
|
||||||
|
case 1
|
||||||
|
when 0.9, 1.1
|
||||||
|
assert(false)
|
||||||
|
when 1.0
|
||||||
|
assert(true)
|
||||||
|
else
|
||||||
|
assert(false)
|
||||||
|
end
|
||||||
|
case 536870912
|
||||||
|
when 536870911.9, 536870912.1
|
||||||
|
assert(false)
|
||||||
|
when 536870912.0
|
||||||
|
assert(true)
|
||||||
|
else
|
||||||
|
assert(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue