FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle argument or block passed to Range#count by headius · Pull Request #8956 · jruby/jruby · GitHub

/ jruby Public

Handle argument or block passed to Range#count - #8956

Merged
headius merged 2 commits into
jruby:masterfrom
headius:range_count_block
Aug 10, 2025
Merged

Handle argument or block passed to Range#count#8956
headius merged 2 commits into
jruby:masterfrom
headius:range_count_block

Conversation

headius commented Aug 10, 2025

Copy link
Copy Markdown
Member

Logic installed to prevent large ranges from manually iterating to calculate a count (79ee920) short-circuited the fallback on Enumerable#count logic. That broke count when passed a block (as described in #8955). Additionally, we did not handle the case where Range#count is passed an argument.

This PR fixes both cases and adds specs.

Block-receiving Range#count should always use Enumerable logic.

Also add single-arg form which falls back on Enumerable.

Fixes jruby#8955
These specs are lightly-modified versions of the same specs from
Enumerable#count, but those specs depend on the Enumerable having
multiple of the same value. A shared spec could probably be pulled
out.

See jruby#8955.
headius added this to the JRuby 10.0.3.0 milestone Aug 10, 2025
headius linked an issue Aug 10, 2025 that may be closed by this pull request
headius merged commit be95012 into jruby:master Aug 10, 2025
73 checks passed
headius deleted the range_count_block branch August 10, 2025 16:43

pboling left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Range#count always returns size for Integer bounds

2 participants


Back | FazBrowse Home | New Git URL