From 48cc5b419f9c16f97cacbb42c6f8282bdd883190 Mon Sep 17 00:00:00 2001 From: Justin Collins Date: Fri, 7 Feb 2014 09:03:54 +0100 Subject: [PATCH] Reuse call locations in CallIndex --- lib/brakeman/processors/lib/find_all_calls.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/brakeman/processors/lib/find_all_calls.rb b/lib/brakeman/processors/lib/find_all_calls.rb index 86f37939..6f3896d3 100644 --- a/lib/brakeman/processors/lib/find_all_calls.rb +++ b/lib/brakeman/processors/lib/find_all_calls.rb @@ -9,6 +9,7 @@ class Brakeman::FindAllCalls < Brakeman::BaseProcessor @current_method = nil @in_target = false @calls = [] + @cache = {} end #Process the given source. Provide either class and method being searched @@ -145,11 +146,18 @@ class Brakeman::FindAllCalls < Brakeman::BaseProcessor def make_location if @current_template - { :type => :template, + key = [@current_template, @current_file] + cached = @cache[key] + return cached if cached + + @cache[key] = { :type => :template, :template => @current_template, :file => @current_file } else - { :type => :class, + key = [@current_class, @current_method, @current_file] + cached = @cache[key] + return cached if cached + @cache[key] = { :type => :class, :class => @current_class, :method => @current_method, :file => @current_file } -- GitLab