Skip to content

Commit 0e30d1e

Browse files
committed
ZJIT: Rename array length reference to make the code easier to follow
1 parent 4c75250 commit 0e30d1e

2 files changed

Lines changed: 31 additions & 31 deletions

File tree

vm_insnhelper.c

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

63466346
static VALUE
6347-
vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6347+
vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
63486348
{
63496349
if (BASIC_OP_UNREDEFINED_P(BOP_MAX, ARRAY_REDEFINED_OP_FLAG)) {
6350-
if (num == 0) {
6350+
if (array_len == 0) {
63516351
return Qnil;
63526352
}
63536353
else {
63546354
VALUE result = *ptr;
6355-
rb_snum_t i = num - 1;
6355+
rb_snum_t i = array_len - 1;
63566356
while (i-- > 0) {
63576357
const VALUE v = *++ptr;
63586358
if (OPTIMIZED_CMP(v, result) > 0) {
@@ -6363,26 +6363,26 @@ vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
63636363
}
63646364
}
63656365
else {
6366-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idMax, 0, NULL, RB_NO_KEYWORDS);
6366+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idMax, 0, NULL, RB_NO_KEYWORDS);
63676367
}
63686368
}
63696369

63706370
VALUE
6371-
rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6371+
rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
63726372
{
6373-
return vm_opt_newarray_max(ec, num, ptr);
6373+
return vm_opt_newarray_max(ec, array_len, ptr);
63746374
}
63756375

63766376
static VALUE
6377-
vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6377+
vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
63786378
{
63796379
if (BASIC_OP_UNREDEFINED_P(BOP_MIN, ARRAY_REDEFINED_OP_FLAG)) {
6380-
if (num == 0) {
6380+
if (array_len == 0) {
63816381
return Qnil;
63826382
}
63836383
else {
63846384
VALUE result = *ptr;
6385-
rb_snum_t i = num - 1;
6385+
rb_snum_t i = array_len - 1;
63866386
while (i-- > 0) {
63876387
const VALUE v = *++ptr;
63886388
if (OPTIMIZED_CMP(v, result) < 0) {
@@ -6393,63 +6393,63 @@ vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
63936393
}
63946394
}
63956395
else {
6396-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idMin, 0, NULL, RB_NO_KEYWORDS);
6396+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idMin, 0, NULL, RB_NO_KEYWORDS);
63976397
}
63986398
}
63996399

64006400
VALUE
6401-
rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6401+
rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
64026402
{
6403-
return vm_opt_newarray_min(ec, num, ptr);
6403+
return vm_opt_newarray_min(ec, array_len, ptr);
64046404
}
64056405

64066406
static VALUE
6407-
vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6407+
vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
64086408
{
64096409
// If Array#hash is _not_ monkeypatched, use the optimized call
64106410
if (BASIC_OP_UNREDEFINED_P(BOP_HASH, ARRAY_REDEFINED_OP_FLAG)) {
6411-
return rb_ary_hash_values(num, ptr);
6411+
return rb_ary_hash_values(array_len, ptr);
64126412
}
64136413
else {
6414-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idHash, 0, NULL, RB_NO_KEYWORDS);
6414+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idHash, 0, NULL, RB_NO_KEYWORDS);
64156415
}
64166416
}
64176417

64186418
VALUE
6419-
rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
6419+
rb_vm_opt_newarray_hash(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr)
64206420
{
6421-
return vm_opt_newarray_hash(ec, num, ptr);
6421+
return vm_opt_newarray_hash(ec, array_len, ptr);
64226422
}
64236423

64246424
VALUE rb_setup_fake_ary(struct RArray *fake_ary, const VALUE *list, long len);
64256425
VALUE rb_ec_pack_ary(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer);
64266426

64276427
static VALUE
6428-
vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE target)
6428+
vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE target)
64296429
{
64306430
if (BASIC_OP_UNREDEFINED_P(BOP_INCLUDE_P, ARRAY_REDEFINED_OP_FLAG)) {
64316431
struct RArray fake_ary = {RBASIC_INIT};
6432-
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, num);
6432+
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, array_len);
64336433
return rb_ary_includes(ary, target);
64346434
}
64356435
else {
64366436
VALUE args[1] = {target};
6437-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idIncludeP, 1, args, RB_NO_KEYWORDS);
6437+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idIncludeP, 1, args, RB_NO_KEYWORDS);
64386438
}
64396439
}
64406440

64416441
VALUE
6442-
rb_vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE target)
6442+
rb_vm_opt_newarray_include_p(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE target)
64436443
{
6444-
return vm_opt_newarray_include_p(ec, num, ptr, target);
6444+
return vm_opt_newarray_include_p(ec, array_len, ptr, target);
64456445
}
64466446

64476447
static VALUE
6448-
vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE fmt, VALUE buffer)
6448+
vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE fmt, VALUE buffer)
64496449
{
64506450
if (BASIC_OP_UNREDEFINED_P(BOP_PACK, ARRAY_REDEFINED_OP_FLAG)) {
64516451
struct RArray fake_ary = {RBASIC_INIT};
6452-
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, num);
6452+
VALUE ary = rb_setup_fake_ary(&fake_ary, ptr, array_len);
64536453
return rb_ec_pack_ary(ec, ary, fmt, (UNDEF_P(buffer) ? Qnil : buffer));
64546454
}
64556455
else {
@@ -6467,20 +6467,20 @@ vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t num, const VALU
64676467
argc++;
64686468
}
64696469

6470-
return rb_vm_call_with_refinements(ec, rb_ary_new4(num, ptr), idPack, argc, args, kw_splat);
6470+
return rb_vm_call_with_refinements(ec, rb_ary_new4(array_len, ptr), idPack, argc, args, kw_splat);
64716471
}
64726472
}
64736473

64746474
VALUE
6475-
rb_vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr, VALUE fmt, VALUE buffer)
6475+
rb_vm_opt_newarray_pack_buffer(rb_execution_context_t *ec, rb_num_t array_len, const VALUE *ptr, VALUE fmt, VALUE buffer)
64766476
{
6477-
return vm_opt_newarray_pack_buffer(ec, num, ptr, fmt, buffer);
6477+
return vm_opt_newarray_pack_buffer(ec, array_len, ptr, fmt, buffer);
64786478
}
64796479

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

64866486
#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)