aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2014-02-27 14:22:43 -0600
committerJack Nagel2014-02-27 14:22:43 -0600
commit74eb25df812889443c38ae462ccaee11a05d5afa (patch)
tree9528eafe6bacbc2b9d21b7a3f943bea67f3f713f /Library
parent1981e78eb2fe7231c999edf86c862597320ec5fe (diff)
downloadbrew-74eb25df812889443c38ae462ccaee11a05d5afa.tar.bz2
Cache and reuse Dependency objects
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/dependency_collector.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb
index 0e3feac8e..2b5cfc704 100644
--- a/Library/Homebrew/dependency_collector.rb
+++ b/Library/Homebrew/dependency_collector.rb
@@ -21,6 +21,8 @@ class DependencyCollector
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
].freeze
+ CACHE = {}
+
attr_reader :deps, :requirements
def initialize
@@ -29,7 +31,7 @@ class DependencyCollector
end
def add(spec)
- case dep = build(spec)
+ case dep = fetch(spec)
when Dependency
@deps << dep
when Requirement
@@ -38,6 +40,18 @@ class DependencyCollector
dep
end
+ def fetch(spec)
+ CACHE.fetch(cache_key(spec)) { |key| CACHE[key] = build(spec) }
+ end
+
+ def cache_key(spec)
+ if Resource === spec && spec.download_strategy == CurlDownloadStrategy
+ File.extname(spec.url)
+ else
+ spec
+ end
+ end
+
def build(spec)
spec, tags = case spec
when Hash then destructure_spec_hash(spec)