Skip to content

Update spec_set to use lookup#9480

Merged
eileencodes merged 1 commit intoruby:masterfrom
OughtPuts:ho/update-spec-set-to-use-lookup
Apr 14, 2026
Merged

Update spec_set to use lookup#9480
eileencodes merged 1 commit intoruby:masterfrom
OughtPuts:ho/update-spec-set-to-use-lookup

Conversation

@OughtPuts
Copy link
Copy Markdown
Contributor

@OughtPuts OughtPuts commented Apr 14, 2026

What was the end-user or developer problem that led to this PR?

Bundler::SpecSet already maintains a name-indexed lookup of specs (lookup), but #find_by_name_and_platform and the special rake handling in #sorted were still scanning @specs directly.

That meant these methods were not taking advantage of the existing indexed structure in the class, even though equivalent information was already available through lookup. The goal of this PR is to make those methods consistent with the rest of SpecSet by reusing the existing lookup instead of doing additional scans.

What is your fix for the problem, implemented in this PR?

This PR updates both call sites to use the existing name-indexed lookup:

  • #find_by_name_and_platform now uses lookup[name]&.detect { ... } instead of scanning all of @specs
  • #sorted now uses lookup["rake"]&.first instead of @specs.find { ... } for the special-case rake preloading behaviour.

The behaviour is intended to remain unchanged.

I also expanded the spec coverage in spec/bundler/spec_set_spec.rb to cover the important regression cases around the refactor:

  • returning the matching platform-specific spec
  • returning nil when the name is missing
  • returning nil when the name exists but no spec is installable on the requested platform
  • preserving the existing behaviour of returning the first matching installable spec
  • preserving the special rake ordering behaviour in #to_a

Make sure the following tasks are checked

@OughtPuts OughtPuts force-pushed the ho/update-spec-set-to-use-lookup branch from 6ff81b3 to 3a90d24 Compare April 14, 2026 09:09
@eileencodes eileencodes merged commit a3ad90f into ruby:master Apr 14, 2026
96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants