From 26a2e4c4d38f111ab89093c12e3532529fc8da0b Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Thu, 1 Jan 2015 01:21:59 -0500 Subject: 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. --- Library/Homebrew/formulary.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Library') 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 -- cgit v1.2.3