From 6ac30826d007089be67518f14401d7b290ebb5d7 Mon Sep 17 00:00:00 2001 From: Emiel Wiedijk Date: Sat, 6 Oct 2018 17:29:34 +0200 Subject: [PATCH 1/2] Remove redundant check in formula_files and cask_files Formula_files consists of every non-recursive child of formula_dir, for which formula_file? evaluates to true. formula_file? checks if the file is a child of formula_dir, which it is by definition. It turns out that by removing the check, the time used for 'brew search' decreased from 800 ms to 700 ms, noticably faster during tab completion. The same happens with cask_files and cask_file? --- Library/Homebrew/tap.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 46160175e5..37534e5312 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -382,7 +382,7 @@ class Tap # an array of all {Formula} files of this {Tap}. def formula_files @formula_files ||= if formula_dir.directory? - formula_dir.children.select(&method(:formula_file?)) + formula_dir.children.select { |file| file.extname == ".rb" } else [] end @@ -391,7 +391,7 @@ class Tap # an array of all {Cask} files of this {Tap}. def cask_files @cask_files ||= if cask_dir.directory? - cask_dir.children.select(&method(:cask_file?)) + cask_dir.children.select { |file| file.extname == ".rb" } else [] end From 0fcdc9ba0726570e29d6ce93956f6a5da4907ba3 Mon Sep 17 00:00:00 2001 From: Emiel Wiedijk Date: Wed, 10 Oct 2018 17:16:18 +0200 Subject: [PATCH 2/2] Create method ruby_file? Both formula_files and cask_files need to check whether a file is a Ruby file. Also, use this method in formula_file? and cask_file? --- Library/Homebrew/tap.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 37534e5312..5895d96db8 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -382,7 +382,7 @@ class Tap # an array of all {Formula} files of this {Tap}. def formula_files @formula_files ||= if formula_dir.directory? - formula_dir.children.select { |file| file.extname == ".rb" } + formula_dir.children.select(&method(:ruby_file?)) else [] end @@ -391,19 +391,25 @@ class Tap # an array of all {Cask} files of this {Tap}. def cask_files @cask_files ||= if cask_dir.directory? - cask_dir.children.select { |file| file.extname == ".rb" } + cask_dir.children.select(&method(:ruby_file?)) else [] end end + # returns true if the file has a Ruby extension + # @private + def ruby_file?(file) + file.extname == ".rb" + end + # return true if given path would present a {Formula} file in this {Tap}. # accepts both absolute path and relative path (relative to this {Tap}'s path) # @private def formula_file?(file) file = Pathname.new(file) unless file.is_a? Pathname file = file.expand_path(path) - file.extname == ".rb" && file.parent == formula_dir + ruby_file?(file) && file.parent == formula_dir end # return true if given path would present a {Cask} file in this {Tap}. @@ -412,7 +418,7 @@ class Tap def cask_file?(file) file = Pathname.new(file) unless file.is_a? Pathname file = file.expand_path(path) - file.extname == ".rb" && file.parent == cask_dir + ruby_file?(file) && file.parent == cask_dir end # an array of all {Formula} names of this {Tap}.