mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9529e46adf
commit
6b4132724a
2 changed files with 14 additions and 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>
|
Sun May 15 10:57:26 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even
|
* vm_insnhelper.c (vm_get_ev_const): warn deprecated constant even
|
||||||
|
|
11
array.c
11
array.c
|
@ -1195,10 +1195,17 @@ rb_ary_elt(VALUE ary, long offset)
|
||||||
VALUE
|
VALUE
|
||||||
rb_ary_entry(VALUE ary, long offset)
|
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) {
|
if (offset < 0) {
|
||||||
offset += RARRAY_LEN(ary);
|
offset += len;
|
||||||
|
if (offset < 0) return Qnil;
|
||||||
}
|
}
|
||||||
return rb_ary_elt(ary, offset);
|
else if (len <= offset) {
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
return ptr[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
|
Loading…
Reference in a new issue