From cd6a57676d9bfc1958fe52002e213aac5537d9a1 Mon Sep 17 00:00:00 2001 From: Piero Dotti Date: Fri, 18 May 2018 15:28:48 +0200 Subject: [PATCH 1/2] Reduce memory allocations * Freezing empty string * use `compact!` instead of compact --- lib/deface/search.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/deface/search.rb b/lib/deface/search.rb index c4f5daf..31a2fd7 100644 --- a/lib/deface/search.rb +++ b/lib/deface/search.rb @@ -10,12 +10,15 @@ def find(details) virtual_path = details[:virtual_path] return [] if virtual_path.nil? - [/^\//, /\.\w+\z/].each { |regex| virtual_path.gsub!(regex, '') } + [/^\//, /\.\w+\z/].each { |regex| virtual_path.gsub!(regex, ''.freeze) } result = [] result << self.all[virtual_path.to_sym].try(:values) + + result = result.flatten + result.compact! - result.flatten.compact.sort_by &:sequence + result.sort_by &:sequence end # finds all overrides that are using a template / parital as there source From 43b8ed05eef86c8861614deab795dabc6c26aaa3 Mon Sep 17 00:00:00 2001 From: Piero Dotti Date: Fri, 18 May 2018 16:01:10 +0200 Subject: [PATCH 2/2] `freeze` empty string --- lib/deface/override.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/deface/override.rb b/lib/deface/override.rb index b37893c..bba1632 100644 --- a/lib/deface/override.rb +++ b/lib/deface/override.rb @@ -196,7 +196,7 @@ def digest # def self.digest(details) overrides = self.find(details) - to_hash = overrides.inject('') { |digest, override| digest << override.digest } + to_hash = overrides.inject(''.freeze) { |digest, override| digest << override.digest } Deface::Digest.hexdigest(to_hash) end