Commit e1b306a2
e1b306a2fd68Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
refactor: consolidate string method detection in scan_features
Replace 30+ individual if/end blocks for @needs_string_helpers with a single compound condition for unconditional string methods and a grouped check for receiver-dependent methods (+, *, [], reverse). Also removes duplicate "+" check. -82 lines.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- e1b306a2fd68
- Parent
- b86193c6fc18
spinel_codegen.rbmodifiedView file
@@ -5444,104 +5444,22 @@
54445444
end54455445
if t == "CallNode"54465446
mname = @nd_name[nid]5447-
if mname == "to_s"5448-
@needs_string_helpers = 15449-
end5450-
if mname == "+"5451-
if @nd_receiver[nid] >= 05452-
rt = infer_type(@nd_receiver[nid])5453-
if rt == "string"5454-
@needs_string_helpers = 15455-
end5456-
end5457-
end5458-
if mname == "upcase"5459-
@needs_string_helpers = 15460-
end5461-
if mname == "<<"5462-
@needs_string_helpers = 15463-
if @nd_receiver[nid] >= 05464-
rt = infer_type(@nd_receiver[nid])5465-
if rt == "string"5466-
@needs_string_helpers = 15467-
end5468-
end5469-
end5470-
if mname == "+"5471-
if @nd_receiver[nid] >= 05472-
rt = infer_type(@nd_receiver[nid])5473-
if rt == "string"5474-
@needs_string_helpers = 15475-
end5476-
end5477-
end5478-
if mname == "downcase"5479-
@needs_string_helpers = 15480-
end5481-
if mname == "strip"5482-
@needs_string_helpers = 15483-
end5484-
if mname == "chomp"5485-
@needs_string_helpers = 15486-
end5487-
if mname == "slice"5488-
@needs_string_helpers = 15489-
end5490-
if mname == "include?"5491-
@needs_string_helpers = 15492-
end5493-
if mname == "start_with?"5494-
@needs_string_helpers = 15495-
end5496-
if mname == "end_with?"5447+
# String methods that always need string helpers5448+
if mname == "to_s" || mname == "upcase" || mname == "downcase" ||5449+
mname == "strip" || mname == "chomp" || mname == "slice" ||5450+
mname == "include?" || mname == "start_with?" || mname == "end_with?" ||5451+
mname == "gsub" || mname == "index" || mname == "sub" || mname == "tr" ||5452+
mname == "ljust" || mname == "rjust" || mname == "capitalize" ||5453+
mname == "count" || mname == "<<"54975454
@needs_string_helpers = 154985455
end54995456
if mname == "split"55005457
@needs_string_helpers = 155015458
@needs_str_array = 155025459
@needs_gc = 15503-
end5504-
if mname == "gsub"5505-
@needs_string_helpers = 15506-
end5507-
if mname == "index"5508-
@needs_string_helpers = 155095460
end5510-
if mname == "sub"5511-
@needs_string_helpers = 15512-
end5513-
if mname == "tr"5514-
@needs_string_helpers = 15515-
end5516-
if mname == "ljust"5517-
@needs_string_helpers = 15518-
end5519-
if mname == "rjust"5520-
@needs_string_helpers = 15521-
end5522-
if mname == "[]"5523-
if @nd_receiver[nid] >= 05524-
rt = infer_type(@nd_receiver[nid])5525-
if rt == "string"5526-
@needs_string_helpers = 15527-
end5528-
end5529-
end5530-
if mname == "reverse"5531-
if @nd_receiver[nid] >= 05532-
rt = infer_type(@nd_receiver[nid])5533-
if rt == "string"5534-
@needs_string_helpers = 15535-
end5536-
end5537-
end5538-
if mname == "capitalize"5539-
@needs_string_helpers = 15540-
end5541-
if mname == "count"5542-
@needs_string_helpers = 15543-
end5544-
if mname == "*"5461+
# Methods that need string helpers only when receiver is string5462+
if mname == "+" || mname == "*" || mname == "[]" || mname == "reverse"55455463
if @nd_receiver[nid] >= 055465464
rt = infer_type(@nd_receiver[nid])55475465
if rt == "string"