Project

General

Profile

Feature #18825 ยป 0001-Emit-special-instruction-for-array-literal-.hash.patch

tenderlovemaking (Aaron Patterson), 06/13/2022 04:48 PM

View differences:

array.c
return rb_exec_recursive_paired(recursive_eql, ary1, ary2, ary2);
}
VALUE
rb_ary_hash_values(long len, const VALUE *elements)
{
long i;
st_index_t h;
VALUE n;
h = rb_hash_start(len);
h = rb_hash_uint(h, (st_index_t)rb_ary_hash_values);
for (i=0; i<len; i++) {
n = rb_hash(elements[i]);
h = rb_hash_uint(h, NUM2LONG(n));
}
h = rb_hash_end(h);
return ST2FIX(h);
}
/*
* call-seq:
* array.hash -> integer
......
static VALUE
rb_ary_hash(VALUE ary)
{
long i;
st_index_t h;
VALUE n;
h = rb_hash_start(RARRAY_LEN(ary));
h = rb_hash_uint(h, (st_index_t)rb_ary_hash);
for (i=0; i<RARRAY_LEN(ary); i++) {
n = rb_hash(RARRAY_AREF(ary, i));
h = rb_hash_uint(h, NUM2LONG(n));
}
h = rb_hash_end(h);
return ST2FIX(h);
return rb_ary_hash_values(RARRAY_LEN(ary), RARRAY_CONST_PTR(ary));
}
/*
compile.c
iobj->insn_id = BIN(opt_newarray_min);
ELEM_REMOVE(&niobj->link);
return COMPILE_OK;
case idHash:
iobj->insn_id = BIN(opt_newarray_hash);
ELEM_REMOVE(&niobj->link);
return COMPILE_OK;
}
}
}
defs/id.def
firstline, predefined = __LINE__+1, %[\
max
min
hash
freeze
nil?
inspect
insns.def
val = vm_opt_newarray_min(ec, num, STACK_ADDR_FROM_TOP(num));
}
DEFINE_INSN
opt_newarray_hash
(rb_num_t num)
(...)
(VALUE val)
/* Same discussion as opt_newarray_max. */
// attr bool leaf = false; /* has rb_funcall() */
// attr rb_snum_t sp_inc = 1 - (rb_snum_t)num;
{
val = vm_opt_newarray_hash(ec, num, STACK_ADDR_FROM_TOP(num));
}
/* super(args) # args.size => num */
DEFINE_INSN
invokesuper
internal/array.h
#define RARRAY_PTR_IN_USE_FLAG FL_USER14
/* array.c */
VALUE rb_ary_hash_values(long len, const VALUE *elements);
VALUE rb_ary_last(int, const VALUE *, VALUE);
void rb_ary_set_len(VALUE, long);
void rb_ary_delete_same(VALUE, VALUE);
vm.c
OP(UMinus, UMINUS), (C(String));
OP(Max, MAX), (C(Array));
OP(Min, MIN), (C(Array));
OP(Hash, HASH), (C(Array));
OP(Call, CALL), (C(Proc));
OP(And, AND), (C(Integer));
OP(Or, OR), (C(Integer));
vm_core.h
BOP_UMINUS,
BOP_MAX,
BOP_MIN,
BOP_HASH,
BOP_CALL,
BOP_AND,
BOP_OR,
vm_insnhelper.c
}
}
static VALUE
vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
{
// If Array#hash is _not_ monkeypatched, use the optimized call
if (BASIC_OP_UNREDEFINED_P(BOP_HASH, ARRAY_REDEFINED_OP_FLAG)) {
return rb_ary_hash_values(num, ptr);
}
else {
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idHash, 0, NULL, RB_NO_KEYWORDS);
}
}
#undef id_cmp
#define IMEMO_CONST_CACHE_SHAREABLE IMEMO_FL_USER0
    (1-1/1)