diff options
| author | Xu Cheng | 2015-06-20 14:46:24 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-06-21 15:20:37 +0800 |
| commit | 37cd547d5c63fa180e5ba504046ad2a7513fbae3 (patch) | |
| tree | 28ec0c87d57c558be5514e626376a273da89e7c7 /Library | |
| parent | adafb6c953b91f338325e3c599e7efbd632d5885 (diff) | |
| download | brew-37cd547d5c63fa180e5ba504046ad2a7513fbae3.tar.bz2 | |
Formula: cache methods' output to reduce io
Closes Homebrew/homebrew#40855.
Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index c89abe253..8335cf96f 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -624,22 +624,22 @@ class Formula # an array of all core {Formula} names def self.core_names - Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, ".rb" }.sort + @core_names ||= Dir["#{HOMEBREW_LIBRARY}/Formula/*.rb"].map{ |f| File.basename f, ".rb" }.sort end # an array of all tap {Formula} names def self.tap_names - Tap.map(&:formula_names).flatten.sort + @tap_names ||= Tap.map(&:formula_names).flatten.sort end # an array of all {Formula} names def self.names - (core_names + tap_names.map { |name| name.split("/")[-1] }).sort.uniq + @names ||= (core_names + tap_names.map { |name| name.split("/")[-1] }).sort.uniq end # an array of all {Formula} names, which the tap formulae have the fully-qualified name def self.full_names - core_names + tap_names + @full_names ||= core_names + tap_names end def self.each @@ -657,14 +657,16 @@ class Formula # An array of all installed {Formula} def self.installed - return [] unless HOMEBREW_CELLAR.directory? - - HOMEBREW_CELLAR.subdirs.map do |rack| - begin - Formulary.from_rack(rack) - rescue FormulaUnavailableError, TapFormulaAmbiguityError - end - end.compact + @installed ||= if HOMEBREW_CELLAR.directory? + HOMEBREW_CELLAR.subdirs.map do |rack| + begin + Formulary.from_rack(rack) + rescue FormulaUnavailableError, TapFormulaAmbiguityError + end + end.compact + else + [] + end end def self.aliases |
