diff options
author | Dan McClory <danmcclory@gmail.com> | 2014-05-02 21:58:02 -0400 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2014-05-11 09:55:24 +0100 |
commit | 291479758baed1ce86a2501e05ededd262611440 (patch) | |
tree | 362d84b435fcd918315af22e698ab7b52a6c17c4 /lib/bundler/index.rb | |
parent | 61f1e0dbdd8d609ca7c08e59b2c7caf68950c922 (diff) | |
download | bundler-291479758baed1ce86a2501e05ededd262611440.tar.gz |
use a hash of hashes instead of an hash of arrays.
Diffstat (limited to 'lib/bundler/index.rb')
-rw-r--r-- | lib/bundler/index.rb | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index 493ac8fa..bddd3298 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -16,17 +16,17 @@ module Bundler def initialize @sources = [] @cache = {} - @specs = Hash.new { |h,k| h[k] = [] } + @specs = Hash.new { |h,k| h[k] = Hash.new } end def initialize_copy(o) super @sources = @sources.dup @cache = {} - @specs = Hash.new { |h,k| h[k] = [] } + @specs = Hash.new { |h,k| h[k] = Hash.new } - o.specs.each do |name, array| - @specs[name] = array.dup + o.specs.each do |name, hash| + @specs[name] = hash.dup end end @@ -75,26 +75,21 @@ module Bundler alias [] search def <<(spec) - arr = specs_by_name(spec.name) + @specs[spec.name]["#{spec.version}:#{spec.platform}"] = spec - arr.delete_if do |s| - same_version?(s.version, spec.version) && s.platform == spec.platform - end - - arr << spec spec end def each(&blk) - specs.values.each do |specs| - specs.each(&blk) + specs.values.each do |spec_sets| + spec_sets.values.each(&blk) end end # returns a list of the dependencies def unmet_dependency_names - dependency_names = specs.values.map do |array_of_s| - array_of_s.map do |s| + dependency_names = specs.values.map do |hash_of_s| + hash_of_s.values.map do |s| s.dependencies.map{|d| d.name } end end.flatten.uniq @@ -106,9 +101,9 @@ module Bundler other.each do |s| if (dupes = search_by_spec(s)) && dupes.any? next unless override_dupes - @specs[s.name] -= dupes + @specs[s.name]["#{s.version}:#{s.platform}"] = s end - @specs[s.name] << s + @specs[s.name]["#{s.version}:#{s.platform}"] = s end self end @@ -138,7 +133,7 @@ module Bundler private def specs_by_name(name) - @specs[name] + @specs[name].values end def search_by_dependency(dependency, base = nil) @@ -165,9 +160,8 @@ module Bundler end def search_by_spec(spec) - specs_by_name(spec.name).select do |s| - same_version?(s.version, spec.version) && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform) - end + spec = @specs[spec.name]["#{spec.version}:#{spec.platform}"] + spec ? [spec] : [] end if RUBY_VERSION < '1.9' |