mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
use RARRAY_AREF() instead of RARRAY_CONST_PTR().
* class.c (rb_keyword_error_new): use RARRAY_AREF() because RARRAY_CONST_PTR() can introduce additional overhead in a futre. Same fixes for other files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d36ab02b95
commit
d3edfdc7d9
4 changed files with 12 additions and 13 deletions
3
class.c
3
class.c
|
@ -1776,14 +1776,13 @@ rb_define_attr(VALUE klass, const char *name, int read, int write)
|
||||||
MJIT_FUNC_EXPORTED VALUE
|
MJIT_FUNC_EXPORTED VALUE
|
||||||
rb_keyword_error_new(const char *error, VALUE keys)
|
rb_keyword_error_new(const char *error, VALUE keys)
|
||||||
{
|
{
|
||||||
const VALUE *ptr = RARRAY_CONST_PTR(keys);
|
|
||||||
long i = 0, len = RARRAY_LEN(keys);
|
long i = 0, len = RARRAY_LEN(keys);
|
||||||
VALUE error_message = rb_sprintf("%s keyword%.*s", error, len > 1, "s");
|
VALUE error_message = rb_sprintf("%s keyword%.*s", error, len > 1, "s");
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
rb_str_cat_cstr(error_message, ": ");
|
rb_str_cat_cstr(error_message, ": ");
|
||||||
while (1) {
|
while (1) {
|
||||||
const VALUE k = ptr[i];
|
const VALUE k = RARRAY_AREF(keys, i);
|
||||||
Check_Type(k, T_SYMBOL); /* wrong hash is given to rb_get_kwargs */
|
Check_Type(k, T_SYMBOL); /* wrong hash is given to rb_get_kwargs */
|
||||||
rb_str_append(error_message, rb_sym2str(k));
|
rb_str_append(error_message, rb_sym2str(k));
|
||||||
if (++i >= len) break;
|
if (++i >= len) break;
|
||||||
|
|
3
enum.c
3
enum.c
|
@ -744,7 +744,8 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; i < RARRAY_LEN(ary); i++) {
|
for (; i < RARRAY_LEN(ary); i++) {
|
||||||
v = rb_funcallv_public(v, id, 1, &RARRAY_CONST_PTR(ary)[i]);
|
VALUE arg = RARRAY_AREF(ary, i);
|
||||||
|
v = rb_funcallv_public(v, id, 1, &arg);
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
8
gc.c
8
gc.c
|
@ -2797,13 +2797,13 @@ define_final0(VALUE obj, VALUE block)
|
||||||
|
|
||||||
/* avoid duplicate block, table is usually small */
|
/* avoid duplicate block, table is usually small */
|
||||||
{
|
{
|
||||||
const VALUE *ptr = RARRAY_CONST_PTR(table);
|
|
||||||
long len = RARRAY_LEN(table);
|
long len = RARRAY_LEN(table);
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
for (i = 0; i < len; i++, ptr++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (rb_funcall(*ptr, idEq, 1, block)) {
|
VALUE recv = RARRAY_AREF(table, i);
|
||||||
return *ptr;
|
if (rb_funcall(recv, idEq, 1, block)) {
|
||||||
|
return recv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
struct.c
11
struct.c
|
@ -138,7 +138,6 @@ static inline int
|
||||||
struct_member_pos(VALUE s, VALUE name)
|
struct_member_pos(VALUE s, VALUE name)
|
||||||
{
|
{
|
||||||
VALUE back = struct_ivar_get(rb_obj_class(s), id_back_members);
|
VALUE back = struct_ivar_get(rb_obj_class(s), id_back_members);
|
||||||
VALUE const * p;
|
|
||||||
long j, mask;
|
long j, mask;
|
||||||
|
|
||||||
if (UNLIKELY(NIL_P(back))) {
|
if (UNLIKELY(NIL_P(back))) {
|
||||||
|
@ -148,7 +147,6 @@ struct_member_pos(VALUE s, VALUE name)
|
||||||
rb_raise(rb_eTypeError, "corrupted struct");
|
rb_raise(rb_eTypeError, "corrupted struct");
|
||||||
}
|
}
|
||||||
|
|
||||||
p = RARRAY_CONST_PTR(back);
|
|
||||||
mask = RARRAY_LEN(back);
|
mask = RARRAY_LEN(back);
|
||||||
|
|
||||||
if (mask <= AREF_HASH_THRESHOLD) {
|
if (mask <= AREF_HASH_THRESHOLD) {
|
||||||
|
@ -158,7 +156,7 @@ struct_member_pos(VALUE s, VALUE name)
|
||||||
mask, RSTRUCT_LEN(s));
|
mask, RSTRUCT_LEN(s));
|
||||||
}
|
}
|
||||||
for (j = 0; j < mask; j++) {
|
for (j = 0; j < mask; j++) {
|
||||||
if (p[j] == name)
|
if (RARRAY_AREF(back, j) == name)
|
||||||
return (int)j;
|
return (int)j;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -173,9 +171,10 @@ struct_member_pos(VALUE s, VALUE name)
|
||||||
j = struct_member_pos_ideal(name, mask);
|
j = struct_member_pos_ideal(name, mask);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (p[j] == name)
|
VALUE e = RARRAY_AREF(back, j);
|
||||||
return FIX2INT(p[j + 1]);
|
if (e == name)
|
||||||
if (!RTEST(p[j])) {
|
return FIX2INT(RARRAY_AREF(back, j + 1));
|
||||||
|
if (!RTEST(e)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
j = struct_member_pos_probe(j, mask);
|
j = struct_member_pos_probe(j, mask);
|
||||||
|
|
Loading…
Add table
Reference in a new issue