mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Avoid redundant filtering in FilteredMap.size()
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. Closes gh-37256 Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>
This commit is contained in:
@@ -56,7 +56,7 @@ final class FilteredMap<K, V extends @Nullable Object> extends AbstractMap<K, V>
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (K k : keySet()) {
|
||||
for (K k : this.delegate.keySet()) {
|
||||
if (this.filter.test(k)) {
|
||||
size++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user