lib/contrast/components/settings.rb in contrast-agent-7.1.0 vs lib/contrast/components/settings.rb in contrast-agent-7.2.0

- old
+ new

@@ -3,10 +3,11 @@ require 'contrast/agent/excluder/excluder' require 'contrast/agent/reporting/settings/sensitive_data_masking' require 'contrast/components/config' require 'contrast/components/logger' +require 'contrast/utils/duck_utils' module Contrast module Components # This component encapsulates the statefulness of settings. # When we say 'settings', we're referring specifically to external @@ -217,9 +218,17 @@ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion) end exclusions.input_exclusions.each do |exclusion| matchers << Contrast::Agent::ExclusionMatcher.new(exclusion) end + # Do not populate the matchers unless we have any. There are certain checks in + # SourceMethod that will safe-guard return if there are no exclusions received. + # The matching operation is expensive, and the excluder calls are made for each + # source, and we do not want to check for exclusions if they are empty. This is + # probably redundant as all exclusions default to empty, but will save useless + # new object creation at very least. + return if Contrast::Utils::DuckUtils.empty_duck?(matchers) + @excluder = Contrast::Agent::Excluder.new(matchers) end # Update the sensitive data masking policy from settings, # received from TS. In case the settings are empty,