summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c11
1 files changed, 9 insertions, 2 deletions
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