Commit afa0b1f2
afa0b1f2aa70Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
refactor: replace 7 more while-loop array iterations with .each blocks
Second batch converting index-based while loops to .each blocks. Covers loops in emit/codegen/scan_captured_locals methods.
Bootstrap verified (diff 0), all benchmarks pass.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- afa0b1f2aa70
- Parent
- 743269d1a4b9
spinel_codegen.rbmodifiedView file
@@ -7435,9 +7435,7 @@
74357435
ltypes = "".split(",")74367436
74377437
empty_params = "".split(",")7438-
i = 07439-
while i < stmts.length7440-
sid = stmts[i]7438+
stmts.each { |sid|74417439
if @nd_type[sid] != "DefNode"74427440
if @nd_type[sid] != "ClassNode"74437441
if @nd_type[sid] != "ConstantWriteNode"@@ -7445,8 +7443,7 @@
74457443
end74467444
end74477445
end7448-
i = i + 17449-
end7446+
}74507447
74517448
# Declare vars for second pass to resolve dependent types74527449
j = 0@@ -7458,9 +7455,7 @@
74587455
lnames2 = "".split(",")74597456
ltypes2 = "".split(",")74607457
7461-
i = 07462-
while i < stmts.length7463-
sid = stmts[i]7458+
stmts.each { |sid|74647459
if @nd_type[sid] != "DefNode"74657460
if @nd_type[sid] != "ClassNode"74667461
if @nd_type[sid] != "ConstantWriteNode"@@ -7470,8 +7465,7 @@
74707465
end74717466
end74727467
end7473-
i = i + 17474-
end7468+
}74757469
# Update types that improved in second pass74767470
j = 074777471
while j < lnames2.length@@ -7543,9 +7537,7 @@
75437537
emit_raw("")75447538
75457539
# Compile main statements7546-
i = 07547-
while i < stmts.length7548-
sid = stmts[i]7540+
stmts.each { |sid|75497541
if @nd_type[sid] != "DefNode"75507542
if @nd_type[sid] != "ClassNode"75517543
if @nd_type[sid] != "ConstantWriteNode"@@ -7553,8 +7545,7 @@
75537545
end75547546
end75557547
end7556-
i = i + 17557-
end7548+
}75587549
75597550
emit_raw(" return 0;")75607551
emit_raw("}")@@ -7985,9 +7976,7 @@
79857976
end79867977
fmt = ""79877978
arg_exprs = "".split(",")7988-
i = 07989-
while i < parts.length7990-
pid = parts[i]7979+
parts.each { |pid|79917980
if @nd_type[pid] == "StringNode"79927981
fmt = fmt + escape_c_format(@nd_content[pid])79937982
else@@ -8029,8 +8018,7 @@
80298018
end80308019
end80318020
end8032-
i = i + 18033-
end8021+
}80348022
result = "sp_sprintf(\"" + fmt + "\""80358023
j = 080368024
while j < arg_exprs.length@@ -10279,9 +10267,7 @@
1027910267
@needs_string_helpers = 11028010268
tmp = new_temp1028110269
emit(" sp_StrStrHash *" + tmp + " = sp_StrStrHash_new();")10282-
k = 010283-
while k < elems.length10284-
el = elems[k]10270+
elems.each { |el|1028510271
if @nd_type[el] == "AssocNode"1028610272
vt = infer_type(@nd_expression[el])1028710273
val = compile_expr(@nd_expression[el])@@ -10298,21 +10284,17 @@
1029810284
end1029910285
emit(" sp_StrStrHash_set(" + tmp + ", " + compile_expr(@nd_key[el]) + ", " + val + ");")1030010286
end10301-
k = k + 110302-
end10287+
}1030310288
return tmp1030410289
end1030510290
@needs_str_int_hash = 11030610291
tmp = new_temp1030710292
emit(" sp_StrIntHash *" + tmp + " = sp_StrIntHash_new();")10308-
k = 010309-
while k < elems.length10310-
el = elems[k]10293+
elems.each { |el|1031110294
if @nd_type[el] == "AssocNode"1031210295
emit(" sp_StrIntHash_set(" + tmp + ", " + compile_expr(@nd_key[el]) + ", " + compile_expr(@nd_expression[el]) + ");")1031310296
end10314-
k = k + 110315-
end10297+
}1031610298
tmp1031710299
end1031810300
@@ -11531,9 +11513,7 @@
1153111513
inner_locals = "".split(",")1153211514
inner_free = "".split(",")1153311515
scan_lambda_free_vars(inner_body, inner_params, inner_locals, inner_free)11534-
k = 011535-
while k < inner_free.length11536-
vn = inner_free[k]11516+
inner_free.each { |vn|1153711517
if not_in(vn, params) == 11153811518
if not_in(vn, locals) == 11153911519
if not_in(vn, free_vars) == 1@@ -11541,8 +11521,7 @@
1154111521
end1154211522
end1154311523
end11544-
k = k + 111545-
end11524+
}1154611525
end1154711526
return1154811527
end