From f0ab09968ed666069c701febe9d87ce92110c2ee Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 30 Mar 2020 20:14:04 +0530 Subject: [PATCH] Reduce array allocations from `StaticFile#path` (#8083) Merge pull request 8083 --- lib/jekyll/static_file.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index 9f988a7b0bd..d3a9b8591cd 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -40,11 +40,13 @@ def initialize(site, base, dir, name, collection = nil) # Returns source file path. def path - # Static file is from a collection inside custom collections directory - if !@collection.nil? && !@site.config["collections_dir"].empty? - File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact) - else - File.join(*[@base, @dir, @name].compact) + @path ||= begin + # Static file is from a collection inside custom collections directory + if !@collection.nil? && !@site.config["collections_dir"].empty? + File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact) + else + File.join(*[@base, @dir, @name].compact) + end end end