Changeset 17809 in josm


Ignore:
Timestamp:
2021-04-20T23:52:31+02:00 (3 years ago)
Author:
simon04
Message:

see #20745 - Avoid heap allocations in StyleCache

Fixup r17805.

Location:
trunk
Files:
2 edited

Legend:

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

    r17805 r17809  
    4646
    4747        if (selected) {
    48             if (s.selectedStyle == null) {
    49                 s.selectedStyle = new DividedScale<>();
    50             }
    51             s.selectedStyle.put(o, r);
     48            s.selectedStyle = (s.selectedStyle == null ? new DividedScale<StyleElementList>() : s.selectedStyle).put(o, r);
    5249        } else {
    53             if (s.plainStyle == null) {
    54                 s.plainStyle = new DividedScale<>();
    55             }
    56             s.plainStyle.put(o, r);
     50            s.plainStyle = (s.plainStyle == null ? new DividedScale<StyleElementList>() : s.plainStyle).put(o, r);
    5751        }
    5852        return s.intern();
     
    8276    @Override
    8377    public boolean equals(Object obj) {
    84         if (obj == null) {
    85             return false;
    86         }
    87         if (getClass() != obj.getClass()) {
    88             return false;
    89         }
     78        if (obj == null) return false;
     79        if (getClass() != obj.getClass()) return false;
    9080        final StyleCache other = (StyleCache) obj;
    9181        return Objects.equals(plainStyle, other.plainStyle) && Objects.equals(selectedStyle, other.selectedStyle);
  • trunk/test/functional/org/openstreetmap/josm/gui/mappaint/StyleCacheTest.java

    r17625 r17809  
    1414
    1515import org.junit.jupiter.api.AfterAll;
    16 import org.junit.jupiter.api.BeforeAll;
    1716import org.junit.jupiter.api.BeforeEach;
    1817import org.junit.jupiter.api.Test;
     
    5352    @RegisterExtension
    5453    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    55     public JOSMTestRules test = new JOSMTestRules().preferences().projection().mapStyles().timeout(60000);
     54    public JOSMTestRules test = new JOSMTestRules().main().preferences().projection().mapStyles().timeout(60000);
    5655
    5756    /**
     
    5958     * @throws Exception If an error occurred during load.
    6059     */
    61     @BeforeAll
    62     public static void load() throws Exception {
     60    @BeforeEach
     61    public void load() throws Exception {
    6362        img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    6463        try (InputStream in = Compression.getUncompressedFileInputStream(new File("nodist/data/neubrandenburg.osm.bz2"))) {
     
    158157                StyleElementList sel = p.a;
    159158                assertNotNull(sel);
    160                 Integer k = counter.get(sel);
    161                 if (k == null) {
    162                     k = 0;
    163                 }
    164                 counter.put(sel, k + 1);
     159                counter.merge(sel, 1, Integer::sum);
    165160            }
    166161        }
Note: See TracChangeset for help on using the changeset viewer.