提交 b41459e5 编写于 作者: J Justin Collins

Use custom deep_clone for Sexp

slightly faster and probably uses less memory
上级 8313a32f
......@@ -63,7 +63,7 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
#Generic replace
if replacement = env[exp] and not duplicate? replacement
result = set_line replacement.deep_clone, exp.line
result = replacement.deep_clone(exp.line)
else
result = exp
end
......@@ -580,20 +580,6 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor
meth_env
end
#Set line nunber for +exp+ and every Sexp it contains. Used when replacing
#expressions, so warnings indicate the correct line.
def set_line exp, line_number
if sexp? exp
exp.original_line(exp.original_line || exp.line)
exp.line line_number
exp.each do |e|
set_line e, line_number
end
end
exp
end
#Finds the inner most call target which is not the target of a call to <<
def find_push_target exp
if call? exp and exp.method == :<<
......
......@@ -14,6 +14,30 @@ class Sexp
raise NoMethodError.new("No method '#{name}' for Sexp", name, args)
end
#Create clone of Sexp and nested Sexps but not their non-Sexp contents.
#If a line number is provided, also sets line/original_line on all Sexps.
def deep_clone line = nil
s = Sexp.new
self.each do |e|
if e.is_a? Sexp
s << e.deep_clone(line)
else
s << e
end
end
if line
s.original_line(self.original_line || self.line)
s.line(line)
else
s.original_line(self.original_line)
s.line(self.line)
end
s
end
def paren
@paren ||= false
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册