From 9ef82ae1e254088e9232ba7e67afa0da9246bc6c Mon Sep 17 00:00:00 2001 From: Richie Thomas Date: Wed, 11 Oct 2017 10:51:19 -0400 Subject: In 'readall.rb', replaced multi-step 'each' loop with one-line method chain of Ruby enumerator methods --- Library/Homebrew/cmd/readall.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index 3591e0c09..0fa1f7c07 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -13,16 +13,8 @@ module Homebrew def readall if ARGV.include?("--syntax") - ruby_files = [] - scan_files = %W[ - #{HOMEBREW_LIBRARY}/*.rb - #{HOMEBREW_LIBRARY}/Homebrew/**/*.rb - ] - Dir.glob(scan_files).each do |rb| - next if rb.include?("/vendor/") - next if rb.include?("/cask/") - ruby_files << rb - end + scan_files = "#{HOMEBREW_LIBRARY}/Homebrew/**/*.rb" + ruby_files = Dir.glob(scan_files).reject{|file| file =~ /vendor|cask/ } Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) end -- cgit v1.2.3 From dfaaada8b6cf09fde47810c9dff79b8165b07ca0 Mon Sep 17 00:00:00 2001 From: richiethomas Date: Fri, 13 Oct 2017 19:33:45 -0400 Subject: Memoize recursive dependency checks; reduces calls to 'f.recursive_dependencies' by an order of magnitude --- Library/Homebrew/cmd/uses.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 0b09e1bf1..5b6319cdc 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -54,11 +54,14 @@ module Homebrew end ignores << "recommended?" if ARGV.include? "--skip-recommended" + memo = {} uses = formulae.select do |f| used_formulae.all? do |ff| begin if recursive deps = f.recursive_dependencies do |dependent, dep| + memo_key = [dependent, dep].to_s + next if memo[memo_key] if dep.recommended? Dependency.prune if ignores.include?("recommended?") || dependent.build.without?(dep) elsif dep.optional? @@ -72,6 +75,7 @@ module Homebrew if dep.is_a?(TapDependency) && !dep.tap.installed? Dependency.keep_but_prune_recursive_deps end + memo[memo_key] = true end dep_formulae = deps.flat_map do |dep| -- cgit v1.2.3 From 99bccaae13b38eeb58c234e48386b2898845f2a1 Mon Sep 17 00:00:00 2001 From: richiethomas Date: Wed, 18 Oct 2017 17:44:09 -0400 Subject: Remove /cask/ from readall file filter --- Library/Homebrew/cmd/readall.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index 0fa1f7c07..f9cc50a9b 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -14,7 +14,7 @@ module Homebrew def readall if ARGV.include?("--syntax") scan_files = "#{HOMEBREW_LIBRARY}/Homebrew/**/*.rb" - ruby_files = Dir.glob(scan_files).reject{|file| file =~ /vendor|cask/ } + ruby_files = Dir.glob(scan_files).reject{|file| file.include? '/vendor/' } Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) end -- cgit v1.2.3 From e5e84eec7d91c5a00949e74da15745204c3ca5d5 Mon Sep 17 00:00:00 2001 From: richiethomas Date: Wed, 18 Oct 2017 18:20:30 -0400 Subject: PR feedback- replace '#{HOMEBREW_LIBRARY}/Homebrew/**/*.rb' with '#{HOMEBREW_LIBRARY_PATH}/**/*.rb' --- Library/Homebrew/cmd/readall.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index f9cc50a9b..c123eba79 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -13,8 +13,8 @@ module Homebrew def readall if ARGV.include?("--syntax") - scan_files = "#{HOMEBREW_LIBRARY}/Homebrew/**/*.rb" - ruby_files = Dir.glob(scan_files).reject{|file| file.include? '/vendor/' } + scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb" + ruby_files = Dir.glob(scan_files).reject{|file| file =~ /vendor|cask/ } Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) end -- cgit v1.2.3 From b135a70c57b059bd42fb2095a7f29e73ce5d6aad Mon Sep 17 00:00:00 2001 From: richiethomas Date: Wed, 18 Oct 2017 18:27:42 -0400 Subject: Fix brew style warnings --- Library/Homebrew/cmd/list.rb | 2 +- Library/Homebrew/cmd/readall.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 436fc1f97..f778541a7 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -39,7 +39,7 @@ module Homebrew filtered_list elsif ARGV.named.empty? if ARGV.include? "--full-name" - full_names = Formula.installed.map(&:full_name).sort &tap_and_name_comparison + full_names = Formula.installed.map(&:full_name).sort(&tap_and_name_comparison) return if full_names.empty? puts Formatter.columns(full_names) else diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index c123eba79..b54405d30 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -14,7 +14,7 @@ module Homebrew def readall if ARGV.include?("--syntax") scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb" - ruby_files = Dir.glob(scan_files).reject{|file| file =~ /vendor|cask/ } + ruby_files = Dir.glob(scan_files).reject { |file| file =~ /vendor|cask/ } Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) end -- cgit v1.2.3 From 43cbf08018c6ed8f3bc2142c368ba7b7c9fcf49e Mon Sep 17 00:00:00 2001 From: richiethomas Date: Fri, 20 Oct 2017 09:36:27 -0400 Subject: Remove memoization from uses.rb, as it doesn't result in the expected time complexity savings --- Library/Homebrew/cmd/readall.rb | 2 +- Library/Homebrew/cmd/uses.rb | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index b54405d30..f870d3a4e 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -14,7 +14,7 @@ module Homebrew def readall if ARGV.include?("--syntax") scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb" - ruby_files = Dir.glob(scan_files).reject { |file| file =~ /vendor|cask/ } + ruby_files = Dir.glob(scan_files).reject { |file| file =~ %r{/(vendor|cask)/} } Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) end diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 5b6319cdc..0b09e1bf1 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -54,14 +54,11 @@ module Homebrew end ignores << "recommended?" if ARGV.include? "--skip-recommended" - memo = {} uses = formulae.select do |f| used_formulae.all? do |ff| begin if recursive deps = f.recursive_dependencies do |dependent, dep| - memo_key = [dependent, dep].to_s - next if memo[memo_key] if dep.recommended? Dependency.prune if ignores.include?("recommended?") || dependent.build.without?(dep) elsif dep.optional? @@ -75,7 +72,6 @@ module Homebrew if dep.is_a?(TapDependency) && !dep.tap.installed? Dependency.keep_but_prune_recursive_deps end - memo[memo_key] = true end dep_formulae = deps.flat_map do |dep| -- cgit v1.2.3