diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-15 07:17:46 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-15 07:17:46 +0000 |
commit | a82ea310a94f036249718a6d384daa3031ee4d0d (patch) | |
tree | 376a40c2834c6e2a161d434439ac4687b9430090 /array.c | |
parent | 0a3fb9af9518e91d68b9b77ca7e69a31827a491f (diff) | |
download | ruby-a82ea310a94f036249718a6d384daa3031ee4d0d.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
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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 |