From 344467a686f8dd52d9cf5ad2402f9060f43b18e1 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Thu, 7 Jul 2011 23:55:37 +0200 Subject: [PATCH] Make remote_specs 300% faster. --- lib/bundler/index.rb | 7 +++++-- lib/bundler/source.rb | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index 4d7f77251dc..c26574fa3cf 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -78,10 +78,13 @@ def each(&blk) end end - def use(other) + def use(other, override_dupes = false) return unless other other.each do |s| - next if search_by_spec(s).any? + if (dupes = search_by_spec(s)) && dupes.any? + next unless override_dupes + @specs[s.name] -= dupes + end @specs[s.name] << s end self diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 29e5139a1d2..3f26e912dfe 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -158,11 +158,17 @@ def normalize_uri(uri) end def fetch_specs - Index.build do |idx| - idx.use installed_specs - idx.use cached_specs if @allow_cached || @allow_remote - idx.use remote_specs if @allow_remote + # remote_specs usually generates a way larger Index than the other + # sources, and large_idx.use small_idx is way faster than + # small_idx.use large_idx. + if @allow_remote + idx = remote_specs.dup + else + idx = Index.new end + idx.use(cached_specs, :override_dupes) if @allow_cached || @allow_remote + idx.use(installed_specs, :override_dupes) + idx end def installed_specs