Skip to content

Commit bb89242

Browse files
committed
Omit local variable definitions only used with LOCAL_PTR()
1 parent 10a2688 commit bb89242

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tool/mk_builtin_loader.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,21 @@ def generate_cexpr(ofile, lineno, line_file, body_lineno, text, locals, func_nam
282282

283283
# Avoid generating fetches of lvars we don't need. This is imperfect as it
284284
# will match text inside strings or other false positives.
285-
local_candidates = text.scan(/[a-zA-Z_][a-zA-Z0-9_]*/)
285+
local_ptrs = []
286+
local_candidates = text.gsub(/\bLOCAL_PTR\(\K[a-zA-Z_][a-zA-Z0-9_]*(?=\))/) {
287+
local_ptrs << $&; ''
288+
}.scan(/[a-zA-Z_][a-zA-Z0-9_]*/)
286289

287290
f.puts '{'
288291
lineno += 1
289292
# locals is nil outside methods
290293
locals&.reverse_each&.with_index{|param, i|
291294
next unless Symbol === param
292-
next unless local_candidates.include?(param.to_s)
295+
param = param.to_s
296+
lvar = local_candidates.include?(param)
297+
next unless lvar or local_ptrs.include?(param)
293298
f.puts "VALUE *const #{param}__ptr = (VALUE *)&ec->cfp->ep[#{-3 - i}];"
294-
f.puts "MAYBE_UNUSED(const VALUE) #{param} = *#{param}__ptr;"
299+
f.puts "MAYBE_UNUSED(const VALUE) #{param} = *#{param}__ptr;" if lvar
295300
lineno += 1
296301
}
297302
f.puts "#line #{body_lineno} \"#{line_file}\""

0 commit comments

Comments
 (0)