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
commit048009e8927f0383fd7d0264eee6b837e37ce36a (patch)
tree42dbfd4ff8ebe57c8efc31944c02149c4d739720 /Library
parent1fdf69b90382c43493a5f62f0020729289db6c70 (diff)
downloadhomebrew-048009e8927f0383fd7d0264eee6b837e37ce36a.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)