зеркало из https://github.com/github/ruby.git
vm_insnhelper.c: inline array aref with integer
internal.h: define inlinable rb_ary_entry_internal. array.c: use rb_ary_entry_internal. * Benchmark ruby --jit mame/optcarrot/bin/optcarrot --benchmark mame/optcarrot/examples/Lan_Master.nes ** Before checksum: 59662 fps: 58.095175012159686 ** After fps: 59.874751599221526 checksum: 59662 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
1012e50ac7
Коммит
1fd816803b
12
array.c
12
array.c
|
@ -1209,17 +1209,7 @@ 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);
|
return rb_ary_entry_internal(ary, offset);
|
||||||
const VALUE *ptr = RARRAY_CONST_PTR(ary);
|
|
||||||
if (len == 0) return Qnil;
|
|
||||||
if (offset < 0) {
|
|
||||||
offset += len;
|
|
||||||
if (offset < 0) return Qnil;
|
|
||||||
}
|
|
||||||
else if (len <= offset) {
|
|
||||||
return Qnil;
|
|
||||||
}
|
|
||||||
return ptr[offset];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
|
16
internal.h
16
internal.h
|
@ -1093,6 +1093,22 @@ VALUE rb_check_to_array(VALUE ary);
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline VALUE
|
||||||
|
rb_ary_entry_internal(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 += len;
|
||||||
|
if (offset < 0) return Qnil;
|
||||||
|
}
|
||||||
|
else if (len <= offset) {
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
return ptr[offset];
|
||||||
|
}
|
||||||
|
|
||||||
/* bignum.c */
|
/* bignum.c */
|
||||||
extern const char ruby_digitmap[];
|
extern const char ruby_digitmap[];
|
||||||
double rb_big_fdiv_double(VALUE x, VALUE y);
|
double rb_big_fdiv_double(VALUE x, VALUE y);
|
||||||
|
|
|
@ -3647,8 +3647,13 @@ vm_opt_aref(VALUE recv, VALUE obj)
|
||||||
}
|
}
|
||||||
else if (RBASIC_CLASS(recv) == rb_cArray &&
|
else if (RBASIC_CLASS(recv) == rb_cArray &&
|
||||||
BASIC_OP_UNREDEFINED_P(BOP_AREF, ARRAY_REDEFINED_OP_FLAG)) {
|
BASIC_OP_UNREDEFINED_P(BOP_AREF, ARRAY_REDEFINED_OP_FLAG)) {
|
||||||
|
if (FIXNUM_P(obj)) {
|
||||||
|
return rb_ary_entry_internal(recv, FIX2LONG(obj));
|
||||||
|
}
|
||||||
|
else {
|
||||||
return rb_ary_aref1(recv, obj);
|
return rb_ary_aref1(recv, obj);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (RBASIC_CLASS(recv) == rb_cHash &&
|
else if (RBASIC_CLASS(recv) == rb_cHash &&
|
||||||
BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG)) {
|
BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG)) {
|
||||||
return rb_hash_aref(recv, obj);
|
return rb_hash_aref(recv, obj);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче