summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-22 00:19:12 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-22 00:19:12 (GMT)
commite480660b85f79d7f6c5fed278e9f521d877620d1 (patch)
treefcef0e0276bc3e1833af7bc2284797746a6669b1 /array.c
parentf36ee4406e3600ea83021779ff26edee543afeff (diff)
vm_insnhelper.c: array aref optimization
* vm_insnhelper.c (vm_opt_aref): optimize on other than fixnum argument too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/array.c b/array.c
index c5d7274..5ec72c6 100644
--- a/array.c
+++ b/array.c
@@ -1284,21 +1284,29 @@ rb_ary_subseq(VALUE ary, long beg, long len)
VALUE
rb_ary_aref(int argc, const VALUE *argv, VALUE ary)
{
- VALUE arg;
- long beg, len;
-
+ rb_check_arity(argc, 1, 2);
if (argc == 2) {
- beg = NUM2LONG(argv[0]);
- len = NUM2LONG(argv[1]);
- if (beg < 0) {
- beg += RARRAY_LEN(ary);
- }
- return rb_ary_subseq(ary, beg, len);
+ return rb_ary_aref2(ary, argv[0], argv[1]);
}
- if (argc != 1) {
- rb_scan_args(argc, argv, "11", NULL, NULL);
+ return rb_ary_aref1(ary, argv[0]);
+}
+
+VALUE
+rb_ary_aref2(VALUE ary, VALUE b, VALUE e)
+{
+ long beg = NUM2LONG(b);
+ long len = NUM2LONG(e);
+ if (beg < 0) {
+ beg += RARRAY_LEN(ary);
}
- arg = argv[0];
+ return rb_ary_subseq(ary, beg, len);
+}
+
+VALUE
+rb_ary_aref1(VALUE ary, VALUE arg)
+{
+ long beg, len;
+
/* special case - speeding up */
if (FIXNUM_P(arg)) {
return rb_ary_entry(ary, FIX2LONG(arg));