diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | array.c | 11 |
2 files changed, 14 insertions, 2 deletions
@@ -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 @@ -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 |