Pass path directly to StandardLoader when possible

Now we can avoid computing the path twice in the common case.
This commit is contained in:
Jack Nagel 2014-04-05 22:03:33 -05:00
parent ca3688e33e
commit e008ceb332

View File

@ -105,8 +105,8 @@ class Formulary
# Loads formulae from Homebrew's provided Library # Loads formulae from Homebrew's provided Library
class StandardLoader < FormulaLoader class StandardLoader < FormulaLoader
def initialize name def initialize name, path=Formula.path(name)
super name, Formula.path(name) super
end end
end end
@ -198,14 +198,15 @@ class Formulary
formula_with_that_name = Formula.path(ref) formula_with_that_name = Formula.path(ref)
if formula_with_that_name.file? and formula_with_that_name.readable? if formula_with_that_name.file? and formula_with_that_name.readable?
return StandardLoader.new(ref) return StandardLoader.new(ref, formula_with_that_name)
end end
# test if the name is a formula alias # test if the name is a formula alias
possible_alias = Pathname.new("#{HOMEBREW_LIBRARY}/Aliases/#{ref}") possible_alias = Pathname.new("#{HOMEBREW_LIBRARY}/Aliases/#{ref}")
if possible_alias.file? if possible_alias.file?
name = possible_alias.resolved_path.basename(".rb").to_s path = possible_alias.resolved_path
return StandardLoader.new(name) name = path.basename(".rb").to_s
return StandardLoader.new(name, path)
end end
possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{ref}.rb") possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{ref}.rb")