Skip to content

Avoid redundant filtering in FilteredMap.size() - #37256

Merged
sbrannen merged 1 commit into
spring-projects:7.0.xfrom
noojung:fix/filtered-map
Sep 14, 2026
Merged

sbrannen merged 1 commit into
spring-projects:7.0.xfrom
noojung:fix/filtered-map

Conversation

@noojung

@noojung noojung commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

FilteredMap.size() iterates over keySet(), which already applies the predicate through a FilteredSet wrapper.
The loop then tests each accepted key a second time.

This PR updates FilteredMap.size() to iterate over delegate.keySet() instead, avoiding redundant evaluations and the creation of a FilteredSet wrapper on every call.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 8, 2026
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Sep 9, 2026
@sbrannen sbrannen self-assigned this Sep 14, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 14, 2026
@sbrannen sbrannen added this to the 7.0.10 milestone Sep 14, 2026
Since keySet() already applies the filter, size() evaluated the
predicate twice for every accepted key.

This commit uses delegate.keySet() instead, avoiding the second
evaluation as well as a FilteredSet and FilteredIterator allocation.

Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>
@sbrannen
sbrannen changed the base branch from main to 7.0.x September 14, 2026 12:18
@sbrannen
sbrannen merged commit 9d1156f into spring-projects:7.0.x Sep 14, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Fixed via 9d1156f

@sbrannen

Copy link
Copy Markdown
Member

This has been merged into 7.0.x and main.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants