Commit fb1ad6cf
fb1ad6cf13ffMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
perf(analyze,codegen): cache parse_id_list empty case too
PR #547 by @apocalypse9949. The existing parse_id_list memoizes
non-empty cache hits via @parse_id_cache + @parse_id_pool but
short-circuits the empty-string case to a freshly-allocated
[] on every call. Bootstrap touches @nd_stmts[nid] etc. for
every AST node, many of which carry no children; each empty
case allocated a fresh array.
The change extends the existing cache to the empty case: a
single shared empty array now serves every caller of
parse_id_list(""), mirroring the non-empty path.
Cherry-picked rather than merged because the PR's branch was
based on an old master and a direct merge would revert the
last ~10 commits worth of fixes. Behavior change is identical
to the PR; the .freeze from the PR's version is omitted
because spinel-Ruby doesn't implement Array#freeze (CRuby gets
the defensive guard; spinel-stage-2 silently treats freeze as
a no-op).
make bootstrap clean, make test 513 pass, optcarrot
checksum 59662 unchanged.
Co-Authored-By: prudhvi [email protected] Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- fb1ad6cf13ff
- Parent
- 7caf9b6db62e
spinel_analyze.rbmodifiedView file
# parsed, so the same IntArray can be shared across callers. Callers # must treat the result as read-only. def parse_id_list(s) if s == "" return [] end if @parse_id_cache.key?(s) return @parse_id_pool[@parse_id_cache[s]] end result = [] bs = s.bytes i = 0 n = bs.length num = 0 while i < n b = bs[i] if b == 44 # ',' result.push(num) num = 0 else num = num * 10 + (b - 48) if s != "" bs = s.bytes i = 0 n = bs.length num = 0 while i < n b = bs[i] if b == 44 # ',' result.push(num) num = 0 else num = num * 10 + (b - 48) end i = i + 1 end i = i + 1 result.push(num) end result.push(num) @parse_id_cache[s] = @parse_id_pool.length @parse_id_pool.push(result) resultspinel_codegen.rbmodifiedView file
Loading diff…