aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorXu Cheng2016-08-05 22:01:32 +0800
committerGitHub2016-08-05 22:01:32 +0800
commita8566c9848122474b92fc8989eec196d5f4fb69b (patch)
tree896c040fb575962be0aeb27bc9a99454f3514d73 /Library/Homebrew/cmd
parent38209aadbfe4fd0c6772467c4bc5c63325d53f6c (diff)
downloadbrew-a8566c9848122474b92fc8989eec196d5f4fb69b.tar.bz2
various: eliminate the usage of `any?` (#638)
`any?` is not the opposite of `empty?`. Besides the case that `[false, nil].any?` will return false, `any?`(O(n)) has much worse performance than `empty?`(O(1)).
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/audit.rb5
-rw-r--r--Library/Homebrew/cmd/bottle.rb12
-rw-r--r--Library/Homebrew/cmd/info.rb8
-rw-r--r--Library/Homebrew/cmd/install.rb2
-rw-r--r--Library/Homebrew/cmd/list.rb2
-rw-r--r--Library/Homebrew/cmd/outdated.rb8
-rw-r--r--Library/Homebrew/cmd/readall.rb6
-rw-r--r--Library/Homebrew/cmd/search.rb2
-rw-r--r--Library/Homebrew/cmd/upgrade.rb8
9 files changed, 29 insertions, 24 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index 5827c054c..7428474d3 100644
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -628,7 +628,8 @@ class FormulaAuditor
fv = FormulaVersions.new(formula, :max_depth => 10)
revision_map = fv.revision_map("origin/master")
- if (revisions = revision_map[formula.version]).any?
+ revisions = revision_map[formula.version]
+ if !revisions.empty?
problem "revision should not decrease" if formula.revision < revisions.max
elsif formula.revision != 0
if formula.stable
@@ -644,7 +645,7 @@ class FormulaAuditor
def audit_legacy_patches
return unless formula.respond_to?(:patches)
legacy_patches = Patch.normalize_legacy_patches(formula.patches).grep(LegacyPatch)
- if legacy_patches.any?
+ unless legacy_patches.empty?
problem "Use the patch DSL instead of defining a 'patches' method"
legacy_patches.each { |p| audit_patch(p) }
end
diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb
index cb83ad570..b61c57d03 100644
--- a/Library/Homebrew/cmd/bottle.rb
+++ b/Library/Homebrew/cmd/bottle.rb
@@ -58,10 +58,10 @@ module Homebrew
next if Metafiles::EXTENSIONS.include? file.extname
linked_libraries = Keg.file_linked_libraries(file, string)
- result ||= linked_libraries.any?
+ result ||= !linked_libraries.empty?
if ARGV.verbose?
- print_filename(string, file) if linked_libraries.any?
+ print_filename(string, file) unless linked_libraries.empty?
linked_libraries.each do |lib|
puts " #{Tty.gray}-->#{Tty.reset} links to #{lib}"
end
@@ -83,7 +83,7 @@ module Homebrew
end
end
- if ARGV.verbose? && text_matches.any?
+ if ARGV.verbose? && !text_matches.empty?
print_filename string, file
text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset|
puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}"
@@ -157,7 +157,7 @@ module Homebrew
versions = FormulaVersions.new(f)
bottle_revisions = versions.bottle_version_map("origin/master")[f.pkg_version]
bottle_revisions.pop if bottle_revisions.last.to_i > 0
- bottle_revision = bottle_revisions.any? ? bottle_revisions.max.to_i + 1 : 0
+ bottle_revision = bottle_revisions.empty? ? 0 : bottle_revisions.max.to_i + 1
end
filename = Bottle::Filename.create(f, Utils::Bottles.tag, bottle_revision)
@@ -287,7 +287,7 @@ module Homebrew
old_spec.send(field) != bottle.send(field)
end
bad_fields.delete(:cellar) if old_spec.cellar == :any && bottle.cellar == :any_skip_relocation
- if bad_fields.any?
+ unless bad_fields.empty?
bottle_path.unlink if bottle_path.exist?
odie "--keep-old is passed but there are changes in: #{bad_fields.join ", "}"
end
@@ -387,7 +387,7 @@ module Homebrew
next if key == "cellar" && old_value == "any" && value == "any_skip_relocation"
mismatches << key if old_value.empty? || value != old_value
end
- if mismatches.any?
+ unless mismatches.empty?
odie "--keep-old was passed but there were changes in #{mismatches.join(", ")}!"
end
output = bottle_output bottle
diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb
index ad68dc8f4..7c483c378 100644
--- a/Library/Homebrew/cmd/info.rb
+++ b/Library/Homebrew/cmd/info.rb
@@ -118,7 +118,7 @@ module Homebrew
attrs << "pinned at #{f.pinned_version}" if f.pinned?
attrs << "keg-only" if f.keg_only?
- puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" if attrs.any?}"
+ puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}"
puts f.desc if f.desc
puts "#{Tty.em}#{f.homepage}#{Tty.reset}" if f.homepage
@@ -126,14 +126,14 @@ module Homebrew
puts "Conflicts with: #{conflicts*", "}" unless conflicts.empty?
kegs = f.installed_kegs.sort_by(&:version)
- if kegs.any?
+ if kegs.empty?
+ puts "Not installed"
+ else
kegs.each do |keg|
puts "#{keg} (#{keg.abv})#{" *" if keg.linked?}"
tab = Tab.for_keg(keg).to_s
puts " #{tab}" unless tab.empty?
end
- else
- puts "Not installed"
end
puts "From: #{Tty.em}#{github_info(f)}#{Tty.reset}"
diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb
index d460452c5..b255e10e8 100644
--- a/Library/Homebrew/cmd/install.rb
+++ b/Library/Homebrew/cmd/install.rb
@@ -82,7 +82,7 @@ module Homebrew
begin
formulae = []
- if ARGV.casks.any?
+ unless ARGV.casks.empty?
args = []
args << "--force" if ARGV.force?
args << "--debug" if ARGV.debug?
diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb
index 78d8e898b..ef7b73919 100644
--- a/Library/Homebrew/cmd/list.rb
+++ b/Library/Homebrew/cmd/list.rb
@@ -28,7 +28,7 @@ module Homebrew
# Unbrewed uses the PREFIX, which will exist
# Things below use the CELLAR, which doesn't until the first formula is installed.
unless HOMEBREW_CELLAR.exist?
- raise NoSuchKegError.new(ARGV.named.first) if ARGV.named.any?
+ raise NoSuchKegError.new(ARGV.named.first) unless ARGV.named.empty?
return
end
diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb
index dfd61226a..a318b65f6 100644
--- a/Library/Homebrew/cmd/outdated.rb
+++ b/Library/Homebrew/cmd/outdated.rb
@@ -17,13 +17,17 @@ require "keg"
module Homebrew
def outdated
- formulae = ARGV.resolved_formulae.any? ? ARGV.resolved_formulae : Formula.installed
+ formulae = if ARGV.resolved_formulae.empty?
+ Formula.installed
+ else
+ ARGV.resolved_formulae
+ end
if ARGV.json == "v1"
outdated = print_outdated_json(formulae)
else
outdated = print_outdated(formulae)
end
- Homebrew.failed = ARGV.resolved_formulae.any? && outdated.any?
+ Homebrew.failed = !ARGV.resolved_formulae.empty? && !outdated.empty?
end
def print_outdated(formulae)
diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb
index 5442e4206..e399e7c2b 100644
--- a/Library/Homebrew/cmd/readall.rb
+++ b/Library/Homebrew/cmd/readall.rb
@@ -22,10 +22,10 @@ module Homebrew
end
options = { :aliases => ARGV.include?("--aliases") }
- taps = if ARGV.named.any?
- [Tap.fetch(ARGV.named.first)]
- else
+ taps = if ARGV.named.empty?
Tap
+ else
+ [Tap.fetch(ARGV.named.first)]
end
taps.each do |tap|
Homebrew.failed = true unless Readall.valid_tap?(tap, options)
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index 71f5d3a8b..9574ba7d6 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -89,7 +89,7 @@ module Homebrew
arg.include?(char) && !arg.start_with?("/")
end
end
- if ARGV.any? && bad_regex
+ if !ARGV.empty? && bad_regex
ohai "Did you mean to perform a regular expression search?"
ohai "Surround your query with /slashes/ to search by regex."
end
diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb
index 382ff6b71..c96d2b1f5 100644
--- a/Library/Homebrew/cmd/upgrade.rb
+++ b/Library/Homebrew/cmd/upgrade.rb
@@ -21,16 +21,16 @@ module Homebrew
if ARGV.named.empty?
outdated = Formula.installed.select(&:outdated?)
exit 0 if outdated.empty?
- elsif ARGV.named.any?
+ else
outdated = ARGV.resolved_formulae.select(&:outdated?)
(ARGV.resolved_formulae - outdated).each do |f|
versions = f.installed_kegs.map { |keg| keg.version }
- if versions.any?
+ if versions.empty?
+ onoe "#{f.full_name} not installed"
+ else
version = versions.max
onoe "#{f.full_name} #{version} already installed"
- else
- onoe "#{f.full_name} not installed"
end
end
exit 1 if outdated.empty?