summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Katz <wycats@Yehuda-Katzs-MacBook-Pro-2.local>2010-11-14 15:39:10 -0600
committerYehuda Katz <wycats@Yehuda-Katzs-MacBook-Pro-2.local>2010-11-15 10:40:21 -0600
commit80015b77826289d999dcb9432268d75c9b8184a1 (patch)
treed5eef6a0a6b68f42d2bca7f75a8fcf5ea89e17cd
parent92d0c96d8bdcfc7bac245cd5141e29d11186e7ea (diff)
downloadbundler-80015b77826289d999dcb9432268d75c9b8184a1.tar.gz
Performance improvements
-rw-r--r--lib/bundler/index.rb23
-rw-r--r--lib/bundler/source.rb33
2 files changed, 35 insertions, 21 deletions
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index f6b45d06dc..1ca9af19a0 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -8,6 +8,9 @@ module Bundler
i
end
+ attr_reader :specs
+ protected :specs
+
def initialize
@cache = {}
@specs = Hash.new { |h,k| h[k] = [] }
@@ -17,7 +20,10 @@ module Bundler
super
@cache = {}
@specs = Hash.new { |h,k| h[k] = [] }
- merge!(o)
+
+ o.specs.each do |name, array|
+ @specs[name] = array.dup
+ end
end
def empty?
@@ -59,7 +65,7 @@ module Bundler
arr = @specs[spec.name]
arr.delete_if do |s|
- s.version == spec.version && s.platform == spec.platform
+ same_version?(s.version, spec.version) && s.platform == spec.platform
end
arr << spec
@@ -91,10 +97,21 @@ module Bundler
def search_by_spec(spec)
@specs[spec.name].select do |s|
- s.version == spec.version && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform)
+ same_version?(s.version, spec.version) && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform)
end
end
+ def same_version?(a, b)
+ regex = /^(.*?)(?:\.0)*$/
+
+ ret = a.to_s[regex, 1] == b.to_s[regex, 1]
+ end
+
+ def spec_satisfies_dependency?(spec, dep)
+ return false unless dep.name === spec.name
+ dep.requirement.satisfied_by?(spec.version)
+ end
+
def search_by_dependency(dependency)
@cache[dependency.hash] ||= begin
specs = @specs[dependency.name]
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index e5eb86f881..685ea47561 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -158,7 +158,7 @@ module Bundler
@installed_specs ||= begin
idx = Index.new
have_bundler = false
- Gem::SourceIndex.from_installed_gems.to_a.reverse.each do |dont_use_this_var, spec|
+ Gem.source_index.to_a.reverse.each do |dont_use_this_var, spec|
next if spec.name == 'bundler' && spec.version.to_s != VERSION
have_bundler = true if spec.name == 'bundler'
spec.source = self
@@ -185,27 +185,24 @@ module Bundler
def cached_specs
@cached_specs ||= begin
- idx = Index.new
- @caches.each do |path|
- Dir["#{path}/*.gem"].each do |gemfile|
- next if gemfile =~ /bundler\-[\d\.]+?\.gem/
-
- # Try to skip decompressing the gem to get at the gemspec if possible
- cached_gemspec = gemfile.gsub(%r{cache/(.*?)\.gem}, 'specifications/\1.gemspec')
- s = Gem::Specification.load(cached_gemspec) if File.exist?(cached_gemspec)
-
- begin
- s ||= Gem::Format.from_file_by_path(gemfile).spec
- rescue Gem::Package::FormatError
- raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted."
- end
+ idx = installed_specs.dup
+
+ path = Bundler.app_cache
+ Dir["#{path}/*.gem"].each do |gemfile|
+ next if gemfile =~ /bundler\-[\d\.]+?\.gem/
- s.source = self
- idx << s
+ begin
+ s ||= Gem::Format.from_file_by_path(gemfile).spec
+ rescue Gem::Package::FormatError
+ raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted."
end
+
+ s.source = self
+ idx << s
end
- idx
end
+
+ idx
end
def remote_specs