summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Arko <andre@arko.net>2012-11-23 20:59:02 -0800
committerAndré Arko <andre@arko.net>2012-11-23 20:59:02 -0800
commit4680712be12c1aa982f163353c300ec564b7f797 (patch)
treeb5e67b973b0ae4cb48e67143a54ae3c7a322be77
parent60ef317ccd8d0801f18ee3058b55574bc76186c9 (diff)
parent8e6654a700bde4d4eabe33c996f3115033583952 (diff)
downloadbundler-4680712be12c1aa982f163353c300ec564b7f797.tar.gz
Merge pull request #2181 from cheald/performance
Performance improvements
-rwxr-xr-x[-rw-r--r--]lib/bundler/lazy_specification.rb9
-rwxr-xr-x[-rw-r--r--]lib/bundler/lockfile_parser.rb36
2 files changed, 30 insertions, 15 deletions
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index b10d142b74..af9baff80b 100644..100755
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -26,8 +26,7 @@ module Bundler
end
def ==(other)
- [name, version, dependencies, platform, source] ==
- [other.name, other.version, other.dependencies, other.platform, other.source]
+ identifier == other.identifier
end
def satisfies?(dependency)
@@ -58,7 +57,11 @@ module Bundler
end
def to_s
- "#{name} (#{version})"
+ @__to_s ||= "#{name} (#{version})"
+ end
+
+ def identifier
+ @__identifier ||= [name, version, source, platform, dependencies].hash
end
private
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index 058633e409..a4be086fd6 100644..100755
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -14,22 +14,31 @@ module Bundler
class LockfileParser
attr_reader :sources, :dependencies, :specs, :platforms
+ DEPENDENCIES = "DEPENDENCIES"
+ PLATFORMS = "PLATFORMS"
+ GIT = "GIT"
+ GEM = "GEM"
+ PATH = "PATH"
+ SPECS = " specs:"
+ OPTIONS = /^ ([a-z]+): (.*)$/i
+
def initialize(lockfile)
@platforms = []
@sources = []
@dependencies = []
- @specs = []
@state = :source
+ @specs = {}
lockfile.split(/(?:\r?\n)+/).each do |line|
- if line == "DEPENDENCIES"
+ if line == DEPENDENCIES
@state = :dependency
- elsif line == "PLATFORMS"
+ elsif line == PLATFORMS
@state = :platform
else
send("parse_#{@state}", line)
end
end
+ @specs = @specs.values
end
private
@@ -42,10 +51,10 @@ module Bundler
def parse_source(line)
case line
- when "GIT", "GEM", "PATH"
+ when GIT, GEM, PATH
@current_source = nil
@opts, @type = {}, line
- when " specs:"
+ when SPECS
@current_source = TYPES[@type].from_lock(@opts)
# Strip out duplicate GIT sections
@@ -54,7 +63,7 @@ module Bundler
end
@sources << @current_source
- when /^ ([a-z]+): (.*)$/i
+ when OPTIONS
value = $2
value = true if value == "true"
value = false if value == "false"
@@ -73,17 +82,20 @@ module Bundler
end
NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'
+ NAME_VERSION_2 = %r{^ {2}#{NAME_VERSION}(!)?$}
+ NAME_VERSION_4 = %r{^ {4}#{NAME_VERSION}$}
+ NAME_VERSION_6 = %r{^ {6}#{NAME_VERSION}$}
def parse_dependency(line)
- if line =~ %r{^ {2}#{NAME_VERSION}(!)?$}
+ if line =~ NAME_VERSION_2
name, version, pinned = $1, $2, $4
version = version.split(",").map { |d| d.strip } if version
dep = Bundler::Dependency.new(name, version)
if pinned && dep.name != 'bundler'
- spec = @specs.find { |s| s.name == dep.name }
- dep.source = spec.source if spec
+ spec = @specs.find {|k, v| v.name == dep.name }
+ dep.source = spec.last.source if spec
# Path sources need to know what the default name / version
# to use in the case that there are no gemspecs present. A fake
@@ -100,7 +112,7 @@ module Bundler
end
def parse_spec(line)
- if line =~ %r{^ {4}#{NAME_VERSION}$}
+ if line =~ NAME_VERSION_4
name, version = $1, Gem::Version.new($2)
platform = $3 ? Gem::Platform.new($3) : Gem::Platform::RUBY
@current_spec = LazySpecification.new(name, version, platform)
@@ -108,8 +120,8 @@ module Bundler
# Avoid introducing multiple copies of the same spec (caused by
# duplicate GIT sections)
- @specs << @current_spec unless @specs.include?(@current_spec)
- elsif line =~ %r{^ {6}#{NAME_VERSION}$}
+ @specs[@current_spec.identifier] ||= @current_spec
+ elsif line =~ NAME_VERSION_6
name, version = $1, $2
version = version.split(',').map { |d| d.strip } if version
dep = Gem::Dependency.new(name, version)