Commit 9f9e5e9b
9f9e5e9b446cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
codegen: String#gsub / #sub block form
The block-form (s.gsub(/re/) { |m| ... }) was a silent no-op
returning the receiver. Emit a per-call inlined re_exec loop
that binds the match to the block param, evaluates the block
body, and splices the result into a growing buffer.
Fixes #849
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 9f9e5e9b446c
- Parent
- 311d75c91241
spinel_analyze.rbmodifiedView file
@@ -30074,6 +30074,11 @@
3007430074
if mname == "each_line"3007530075
return "string"3007630076
end30077+
# Issue #849: gsub/sub block form. Each match is yielded as30078+
# a string to the block; block returns the replacement string.30079+
if mname == "gsub" || mname == "sub"30080+
return "string"30081+
end3007730082
if mname == "each_pair"3007830083
# Hash#each_pair: key, value. Mirror scan_locals.3007930084
if recv_t == "str_int_hash"spinel_codegen.rbmodifiedView file
Loading diff…
test/string_gsub_block.rbaddedView file
Loading diff…