diff options
| author | Jack Nagel | 2015-01-01 01:21:59 -0500 |
|---|---|---|
| committer | Jack Nagel | 2015-01-01 13:21:29 -0500 |
| commit | 26a2e4c4d38f111ab89093c12e3532529fc8da0b (patch) | |
| tree | c9cc5607448a78d2239812706e71d5bb83fda72d | |
| parent | 34fc227f92279a5991014c2d825a013c7e90aabe (diff) | |
| download | brew-26a2e4c4d38f111ab89093c12e3532529fc8da0b.tar.bz2 | |
Avoid formula lookup when we know it will fail
Formulary.loader_for cannot raise exceptions, as canonical_name must
work for nonexistent formulae. However, we can skip the constant lookup
and a redundant file existence check by returning a loader that raises
immediately in #get_formula.
| -rw-r--r-- | Library/Homebrew/formulary.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 8fbf8113d..74b506d7d 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -165,6 +165,16 @@ class Formulary end end + class NullLoader < FormulaLoader + def initialize(name) + @name = name + end + + def get_formula(spec) + raise FormulaUnavailableError.new(name) + end + end + # Return a Formula instance for the given reference. # `ref` is string containing: # * a formula name @@ -208,6 +218,6 @@ class Formulary return FormulaLoader.new(ref, possible_cached_formula) end - return FormulaLoader.new(ref, Formula.path(ref)) + return NullLoader.new(ref) end end |
