Skip to content

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

Open
noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix/filtered-map
Open

Avoid redundant filtering in FilteredMap.size()#37256
noojung wants to merge 1 commit into
spring-projects:mainfrom
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.

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>
@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
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) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants