summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-11-04 14:08:59 -0800
committerTim Smith <tsmith84@gmail.com>2020-11-04 14:08:59 -0800
commitfa6614b06d26f987d585dd97dd4de14af92ce2ea (patch)
tree22389d093b89889bfdde196e13963d441ee9116d
parent69147fc6d93b120040c735318b6fc1d09a638933 (diff)
downloadchef-compact.tar.gz
Use .compact instead of .select/.reject to remove nilscompact
This is 3-5x faster from the benchmarks I've run locally. There's a cop coming in the next release of RuboCop to enforce this going forward. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/exceptions.rb2
-rw-r--r--lib/chef/provider/package/chocolatey.rb4
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index 16134fe44b..e0b534c3d3 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -451,7 +451,7 @@ class Chef
attr_reader :wrapped_errors
def initialize(*errors)
- errors = errors.select { |e| !e.nil? }
+ errors = errors.compact
output = "Found #{errors.size} errors, they are stored in the backtrace"
@wrapped_errors = errors
super output
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index 156568e584..06db3c2979 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -79,7 +79,7 @@ class Chef
name_versions_to_install = desired_name_versions.select { |n, v| lowercase_names(names).include?(n) }
name_nil_versions = name_versions_to_install.select { |n, v| v.nil? }
- name_has_versions = name_versions_to_install.reject { |n, v| v.nil? }
+ name_has_versions = name_versions_to_install.compact
# choco does not support installing multiple packages with version pins
name_has_versions.each do |name, version|
@@ -101,7 +101,7 @@ class Chef
name_versions_to_install = desired_name_versions.select { |n, v| lowercase_names(names).include?(n) }
name_nil_versions = name_versions_to_install.select { |n, v| v.nil? }
- name_has_versions = name_versions_to_install.reject { |n, v| v.nil? }
+ name_has_versions = name_versions_to_install.compact
# choco does not support installing multiple packages with version pins
name_has_versions.each do |name, version|