Changeset 16061 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-03-07T23:45:20+01:00 (5 years ago)
Author:
simon04
Message:

SubclassFilteredCollection: use spliteratorUnknownSize() to avoid expensive call to size()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/SubclassFilteredCollection.java

    r13919 r16061  
    77import java.util.NoSuchElementException;
    88import java.util.Objects;
     9import java.util.Spliterator;
     10import java.util.Spliterators;
    911import java.util.function.Predicate;
    1012
     
    8789
    8890    @Override
     91    public Spliterator<T> spliterator() {
     92        return Spliterators.spliteratorUnknownSize(iterator(), 0);
     93    }
     94
     95    @Override
    8996    public int size() {
    9097        if (size == -1) {
    9198            size = 0;
    92             Iterator<T> it = iterator();
    93             while (it.hasNext()) {
    94                 size++;
    95                 it.next();
    96             }
     99            forEach(t -> size++);
    97100        }
    98101        return size;
Note: See TracChangeset for help on using the changeset viewer.