Commit 5add1885
5add188573b1Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
perf(codegen): peephole literal "".split(literal) → sp_StrArray_new()
The empty-StrArray idiom "".split(",") was emitting sp_str_split which strlen-scans the receiver and the separator before returning an empty StrArray. When both receiver and separator are string literals, skip the scan and emit a direct sp_StrArray_new() call.
Hits ~225 sites in spinel_codegen.rb itself, gaining ~2-2.5% wall-clock on the self-codegen workload. 88 tests + 55 benches green; bootstrap fixed-point clean.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 5add188573b1
- Parent
- 6161955724a9
spinel_codegen.rbmodifiedView file
@@ -13555,6 +13555,12 @@
1355513555
if ridx >= 01355613556
return "sp_re_split(sp_re_pat_" + ridx.to_s + ", " + rc + ")"1355713557
end13558+
# Peephole: literal "".split(literal) is the empty-StrArray idiom;13559+
# skip the strlen+sep scan and emit a direct allocator call.13560+
recv = @nd_receiver[nid]13561+
if recv >= 0 && @nd_type[recv] == "StringNode" && @nd_content[recv] == "" && @nd_type[a[0]] == "StringNode"13562+
return "sp_StrArray_new()"13563+
end1355813564
end1355913565
end1356013566
return "sp_str_split(" + rc + ", " + compile_arg0(nid) + ")"