Skip to content

Commit 604fc05

Browse files
nirvdrumtekknolagi
authored andcommitted
ZJIT: Rename array length reference to make the code easier to follow
1 parent 2447380 commit 604fc05

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

vm_insnhelper.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6350,15 +6350,15 @@ rb_vm_opt_duparray_include_p(rb_execution_context_t *ec, const VALUE ary, VALUE
63506350
}
63516351

63526352
static VALUE
6353-
vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6353+
vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
63546354
{
63556355
if (BASIC_OP_UNREDEFINED_P(BOP_MAX, ARRAY_REDEFINED_OP_FLAG)) {
6356-
if (num == 0) {
6356+
if (array_len == 0) {
63576357
return Qnil;
63586358
}
63596359
else {
63606360
VALUE result = *ptr;
6361-
rb_snum_t i = num - 1;
6361+
rb_snum_t i = array_len - 1;
63626362
while (i-- > 0) {
63636363
const VALUE v = *++ptr;
63646364
if (OPTIMIZED_CMP(v, result) > 0) {
@@ -6369,26 +6369,26 @@ vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
63696369
}
63706370
}
63716371
else {
6372-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idMax, 0, NULL, RB_NO_KEYWORDS);
6372+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idMax, 0, NULL, RB_NO_KEYWORDS);
63736373
}
63746374
}
63756375

63766376
VALUE
6377-
rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6377+
rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
63786378
{
6379-
return vm_opt_newarray_max(ec, num, ptr);
6379+
return vm_opt_newarray_max(ec, array_len, ptr);
63806380
}
63816381

63826382
static VALUE
6383-
vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6383+
vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
63846384
{
63856385
if (BASIC_OP_UNREDEFINED_P(BOP_MIN, ARRAY_REDEFINED_OP_FLAG)) {
6386-
if (num == 0) {
6386+
if (array_len == 0) {
63876387
return Qnil;
63886388
}
63896389
else {
63906390
VALUE result = *ptr;
6391-
rb_snum_t i = num - 1;
6391+
rb_snum_t i = array_len - 1;
63926392
while (i-- > 0) {
63936393
const VALUE v = *++ptr;
63946394
if (OPTIMIZED_CMP(v, result) < 0) {
@@ -6399,63 +6399,63 @@ vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
63996399
}
64006400
}
64016401
else {
6402-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idMin, 0, NULL, RB_NO_KEYWORDS);
6402+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idMin, 0, NULL, RB_NO_KEYWORDS);
64036403
}
64046404
}
64056405

64066406
VALUE
6407-
rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6407+
rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
64086408
{
6409-
return vm_opt_newarray_min(ec, num, ptr);
6409+
return vm_opt_newarray_min(ec, array_len, ptr);
64106410
}
64116411

64126412
static VALUE
6413-
vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6413+
vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
64146414
{
64156415
// If Array#hash is _not_ monkeypatched, use the optimized call
64166416
if (BASIC_OP_UNREDEFINED_P(BOP_HASH, ARRAY_REDEFINED_OP_FLAG)) {
6417-
return rb_ary_hash_values(num, ptr);
6417+
return rb_ary_hash_values(array_len, ptr);
64186418
}
64196419
else {
6420-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idHash, 0, NULL, RB_NO_KEYWORDS);
6420+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idHash, 0, NULL, RB_NO_KEYWORDS);
64216421
}
64226422
}
64236423

64246424
VALUE
6425-
rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6425+
rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
64266426
{
6427-
return vm_opt_newarray_hash(ec, num, ptr);
6427+
return vm_opt_newarray_hash(ec, array_len, ptr);
64286428
}
64296429

64306430
VALUE rb_setup_fake_ary(struct RArray *fake_ary, const VALUE *list, long len);
64316431
VALUE rb_ec_pack_ary(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer);
64326432

64336433
static VALUE
6434-
vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE target)
6434+
vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE target)
64356435
{
64366436
if (BASIC_OP_UNREDEFINED_P(BOP_INCLUDE_P, ARRAY_REDEFINED_OP_FLAG)) {
64376437
struct RArray fake_ary = {RBASIC_INIT};
6438-
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, num);
6438+
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, array_len);
64396439
return rb_ary_includes(ary, target);
64406440
}
64416441
else {
64426442
VALUE args[1] = {target};
6443-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idIncludeP, 1, args, RB_NO_KEYWORDS);
6443+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idIncludeP, 1, args, RB_NO_KEYWORDS);
64446444
}
64456445
}
64466446

64476447
VALUE
6448-
rb_vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE target)
6448+
rb_vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE target)
64496449
{
6450-
return vm_opt_newarray_include_p(ec, num, ptr, target);
6450+
return vm_opt_newarray_include_p(ec, array_len, ptr, target);
64516451
}
64526452

64536453
static VALUE
6454-
vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE fmt, VALUE buffer)
6454+
vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE fmt, VALUE buffer)
64556455
{
64566456
if (BASIC_OP_UNREDEFINED_P(BOP_PACK, ARRAY_REDEFINED_OP_FLAG)) {
64576457
struct RArray fake_ary = {RBASIC_INIT};
6458-
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, num);
6458+
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, array_len);
64596459
return rb_ec_pack_ary(ec, ary, fmt, (UNDEF_P(buffer) ? Qnil : buffer));
64606460
}
64616461
else {
@@ -6473,20 +6473,20 @@ vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t num, const VALU
64736473
argc++;
64746474
}
64756475

6476-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idPack, argc, args, kw_splat);
6476+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idPack, argc, args, kw_splat);
64776477
}
64786478
}
64796479

64806480
VALUE
6481-
rb_vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE fmt, VALUE buffer)
6481+
rb_vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE fmt, VALUE buffer)
64826482
{
6483-
return vm_opt_newarray_pack_buffer(ec, num, ptr, fmt, buffer);
6483+
return vm_opt_newarray_pack_buffer(ec, array_len, ptr, fmt, buffer);
64846484
}
64856485

64866486
VALUE
6487-
rb_vm_opt_newarray_pack(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE fmt)
6487+
rb_vm_opt_newarray_pack(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE fmt)
64886488
{
6489-
return vm_opt_newarray_pack_buffer(ec, num, ptr, fmt, Qundef);
6489+
return vm_opt_newarray_pack_buffer(ec, array_len, ptr, fmt, Qundef);
64906490
}
64916491

64926492
#undef id_cmp

zjit/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ fn gen_array_include(
14361436
) -> lir::Opnd {
14371437
gen_prepare_non_leaf_call(jit, asm, state);
14381438

1439-
let num: c_long = elements.len().try_into().expect("Unable to fit length of elements into c_long");
1439+
let array_len: c_long = elements.len().try_into().expect("Unable to fit length of elements into c_long");
14401440

14411441
// After gen_prepare_non_leaf_call, the elements are spilled to the Ruby stack.
14421442
// The elements are at the bottom of the virtual stack, followed by the target.
@@ -1450,7 +1450,7 @@ fn gen_array_include(
14501450
asm_ccall!(
14511451
asm,
14521452
rb_vm_opt_newarray_include_p,
1453-
EC, num.into(), elements_ptr, target
1453+
EC, array_len.into(), elements_ptr, target
14541454
)
14551455
}
14561456

0 commit comments

Comments
 (0)