summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-06-01 13:15:43 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-06-01 13:15:43 +0900
commit65e63af377bb493dea4d0207627ed87d5da360a8 (patch)
tree06871344ac6e5800a9c06387d52f2ce942c04609 /vm_insnhelper.c
parent7df65ef67691fcc354d819da9cd54a1ade9b6247 (diff)
Make opt_aref instruction support Integer#[]
only when its receiver and the argument are both Integers. Since 6bedbf4625, Integer#[] has supported a range extraction. This means that Integer#[] now accepts multiple arguments, which made the method very slow unfortunately. This change fixes the performance issue by adding a special handling for its traditional use case: `num[idx]` where both `num` and `idx` are Integers.
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 7946f9aa4f..3cd0c8df7b 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -4129,6 +4129,10 @@ static VALUE
vm_opt_aref(VALUE recv, VALUE obj)
{
if (SPECIAL_CONST_P(recv)) {
+ if (FIXNUM_P(recv) && FIXNUM_P(obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_AREF, INTEGER_REDEFINED_OP_FLAG)) {
+ return rb_fix_aref(recv, obj);
+ }
return Qundef;
}
else if (RBASIC_CLASS(recv) == rb_cArray &&