diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-11-03 15:15:32 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2021-07-28 10:20:29 -0700 |
commit | d0b08c09e1664108d1e59ac5e92ab264a295d111 (patch) | |
tree | 718f0ae0da0cd3c1ccd8cbe704c4232a8294464e | |
parent | 0e041b5a6f75cf9de31d5c926a9f9b4528d2c86b (diff) | |
download | chef-d0b08c09e1664108d1e59ac5e92ab264a295d111.tar.gz |
Avoid calculating self.etc_chef_dir multiple times on startup
Running chef-apply we calculated this value 5 times. We also have several other resources that use this method which would again have to be calculated. Each of those calculations run the PathHelper.join which involves a whole series of terrible string manipulations. Just calculate this once and be done with it.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 3eb8c8475c..c5e849a586 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -84,8 +84,10 @@ module ChefConfig # @return [String] the platform-specific path # def self.etc_chef_dir(windows: ChefUtils.windows?) - path = windows ? c_chef_dir : PathHelper.join("/etc", ChefUtils::Dist::Infra::DIR_SUFFIX, windows: windows) - PathHelper.cleanpath(path, windows: windows) + @etc_chef_dir ||= begin + path = windows ? c_chef_dir : PathHelper.join("/etc", ChefUtils::Dist::Infra::DIR_SUFFIX, windows: windows) + PathHelper.cleanpath(path, windows: windows) + end end # On *nix, /var/chef, on Windows C:\chef |