Skip to content

Commit

Permalink
Avoid unnecessary loop
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Nov 17, 2021
1 parent b063510 commit afaf868
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -691,21 +691,15 @@ def converge_dependencies
# generated
def converge_locked_specs
deps = []

# Build a list of dependencies that are the same in the Gemfile
# and Gemfile.lock. If the Gemfile modified a dependency, but
# the gem in the Gemfile.lock still satisfies it, this is fine
# too.
@dependencies.each do |dep|
if satisfies_locked_spec?(dep)
deps << dep
end
end

converged = []
@locked_specs.each do |s|
# Replace the locked dependency's source with the equivalent source from the Gemfile
dep = @dependencies.find {|d| s.satisfies?(d) }

if dep && (!dep.source || s.source.include?(dep.source))
deps << dep
end

s.source = (dep && dep.source) || sources.get(s.source) unless multisource_allowed?

# Don't add a spec to the list if its source is expired. For example,
Expand Down Expand Up @@ -763,10 +757,6 @@ def converge_locked_specs
resolve
end

def satisfies_locked_spec?(dep)
@locked_specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) }
end

def metadata_dependencies
@metadata_dependencies ||= begin
ruby_versions = ruby_version_requirements(@ruby_version)
Expand Down

0 comments on commit afaf868

Please sign in to comment.