mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Omit local variable definitions only used with LOCAL_PTR()
This commit is contained in:
parent
10a2688fc4
commit
bb8924240d
1 changed files with 8 additions and 3 deletions
|
@ -282,16 +282,21 @@ def generate_cexpr(ofile, lineno, line_file, body_lineno, text, locals, func_nam
|
||||||
|
|
||||||
# Avoid generating fetches of lvars we don't need. This is imperfect as it
|
# Avoid generating fetches of lvars we don't need. This is imperfect as it
|
||||||
# will match text inside strings or other false positives.
|
# will match text inside strings or other false positives.
|
||||||
local_candidates = text.scan(/[a-zA-Z_][a-zA-Z0-9_]*/)
|
local_ptrs = []
|
||||||
|
local_candidates = text.gsub(/\bLOCAL_PTR\(\K[a-zA-Z_][a-zA-Z0-9_]*(?=\))/) {
|
||||||
|
local_ptrs << $&; ''
|
||||||
|
}.scan(/[a-zA-Z_][a-zA-Z0-9_]*/)
|
||||||
|
|
||||||
f.puts '{'
|
f.puts '{'
|
||||||
lineno += 1
|
lineno += 1
|
||||||
# locals is nil outside methods
|
# locals is nil outside methods
|
||||||
locals&.reverse_each&.with_index{|param, i|
|
locals&.reverse_each&.with_index{|param, i|
|
||||||
next unless Symbol === param
|
next unless Symbol === param
|
||||||
next unless local_candidates.include?(param.to_s)
|
param = param.to_s
|
||||||
|
lvar = local_candidates.include?(param)
|
||||||
|
next unless lvar or local_ptrs.include?(param)
|
||||||
f.puts "VALUE *const #{param}__ptr = (VALUE *)&ec->cfp->ep[#{-3 - i}];"
|
f.puts "VALUE *const #{param}__ptr = (VALUE *)&ec->cfp->ep[#{-3 - i}];"
|
||||||
f.puts "MAYBE_UNUSED(const VALUE) #{param} = *#{param}__ptr;"
|
f.puts "MAYBE_UNUSED(const VALUE) #{param} = *#{param}__ptr;" if lvar
|
||||||
lineno += 1
|
lineno += 1
|
||||||
}
|
}
|
||||||
f.puts "#line #{body_lineno} \"#{line_file}\""
|
f.puts "#line #{body_lineno} \"#{line_file}\""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue