Ignore:
Timestamp:
2021-04-19T21:45:11+02:00 (3 years ago)
Author:
simon04
Message:

see #20745 - Avoid heap allocations via Selector.AbstractSelector#conds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r17781 r17800  
    88import java.text.MessageFormat;
    99import java.util.ArrayList;
     10import java.util.Arrays;
    1011import java.util.Collection;
    1112import java.util.Collections;
     
    215216                    return;
    216217                int count = counter.getAsInt();
    217                 if (link.conds == null || link.conds.isEmpty()) {
     218                if (link.getConditions().isEmpty()) {
    218219                    // index is not needed, we can avoid the sequential search below
    219220                    e.parent = parent;
     
    235236
    236237            private boolean firstAndLastOnly() {
    237                 return link.conds.stream().allMatch(c -> c instanceof IndexCondition && ((IndexCondition) c).isFirstOrLast);
     238                return link.getConditions().stream().allMatch(c -> c instanceof IndexCondition && ((IndexCondition) c).isFirstOrLast);
    238239            }
    239240
     
    574575                }
    575576            } else if (ChildOrParentSelectorType.CHILD == type
    576                     && link.conds != null && !link.conds.isEmpty()
    577                     && link.conds.get(0) instanceof OpenEndPseudoClassCondition) {
     577                    && !link.getConditions().isEmpty()
     578                    && link.getConditions().get(0) instanceof OpenEndPseudoClassCondition) {
    578579                if (e.osm instanceof INode) {
    579580                    e.osm.visitReferrers(new MultipolygonOpenEndFinder(e));
     
    638639    abstract class AbstractSelector implements Selector {
    639640
    640         protected final List<Condition> conds;
     641        private final Condition[] conds;
    641642
    642643        protected AbstractSelector(List<Condition> conditions) {
    643             this.conds = Utils.toUnmodifiableList(conditions);
     644            this.conds = conditions.toArray(new Condition[0]);
    644645        }
    645646
     
    666667        @Override
    667668        public List<Condition> getConditions() {
    668             return conds;
     669            return Arrays.asList(conds);
    669670        }
    670671    }
     
    703704        @Override
    704705        public String toString() {
    705             return "LinkSelector{conditions=" + conds + '}';
     706            return "LinkSelector{conditions=" + getConditions() + '}';
    706707        }
    707708    }
     
    832833            return base
    833834                    + (Range.ZERO_TO_INFINITY.equals(range) ? "" : range)
    834                     + (conds != null ? conds.stream().map(String::valueOf).collect(Collectors.joining("")) : "")
     835                    + (getConditions().stream().map(String::valueOf).collect(Collectors.joining("")))
    835836                    + (subpart != null && subpart != Subpart.DEFAULT_SUBPART ? ("::" + subpart) : "");
    836837        }
Note: See TracChangeset for help on using the changeset viewer.