aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-15 07:17:46 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-15 07:17:46 +0000
commit6b4132724aeb5cf25307a04fd7001065526873c9 (patch)
tree376a40c2834c6e2a161d434439ac4687b9430090
parent9529e46adf33ce88bb7804f0dd1dda96cd4ab1bb (diff)
downloadruby-6b4132724aeb5cf25307a04fd7001065526873c9.tar.gz
* array.c (rb_ary_entry): extract rb_ary_elt to organize if-conditions
and check whether is is embdeded at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--array.c11
2 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1d951600b9..61ca0f78cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun May 15 16:15:25 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * array.c (rb_ary_entry): extract rb_ary_elt to organize if-conditions
+ and check whether is is embdeded at once.
+
Sun May 15 10:57:26 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even
diff --git a/array.c b/array.c
index 8b68320fa0..11fba55029 100644
--- a/array.c
+++ b/array.c
@@ -1195,10 +1195,17 @@ rb_ary_elt(VALUE ary, long offset)
VALUE
rb_ary_entry(VALUE ary, long offset)
{
+ long len = RARRAY_LEN(ary);
+ const VALUE *ptr = RARRAY_CONST_PTR(ary);
+ if (len == 0) return Qnil;
if (offset < 0) {
- offset += RARRAY_LEN(ary);
+ offset += len;
+ if (offset < 0) return Qnil;
+ }
+ else if (len <= offset) {
+ return Qnil;
}
- return rb_ary_elt(ary, offset);
+ return ptr[offset];
}
VALUE