From 65e63af377bb493dea4d0207627ed87d5da360a8 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Sat, 1 Jun 2019 13:15:43 +0900 Subject: 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. --- numeric.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 336ff7066a..1fce19ac0b 100644 --- a/numeric.c +++ b/numeric.c @@ -4630,8 +4630,8 @@ rb_int_rshift(VALUE x, VALUE y) return Qnil; } -static VALUE -fix_aref(VALUE fix, VALUE idx) +MJIT_FUNC_EXPORTED VALUE +rb_fix_aref(VALUE fix, VALUE idx) { long val = FIX2LONG(fix); long i; @@ -4722,7 +4722,7 @@ int_aref1(VALUE num, VALUE arg) one_bit: if (FIXNUM_P(num)) { - return fix_aref(num, arg); + return rb_fix_aref(num, arg); } else if (RB_TYPE_P(num, T_BIGNUM)) { return rb_big_aref(num, arg); -- cgit v1.2.3