Changeset 18823 in josm for trunk/test/unit


Ignore:
Timestamp:
2023-09-06T22:04:23+02:00 (19 months ago)
Author:
taylor.smock
Message:

Improve performance for TaggingPresetSelector$PresetClassifications.getMatchingPresets

This was found when profiling with the Name Suggestion Index enabled.

The improvements are as follows:

  • ~80% reduction in CPU usage
  • ~85% reduction in memory allocations

A good chunk of the remaining cpu cycles and memory allocations is from the sort
operation.

Non-performance related changes are as follows:

  • Add documentation
  • Lint fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelectorTest.java

    r17275 r18823  
    22package org.openstreetmap.josm.gui.tagging.presets;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
     4import static org.junit.jupiter.api.Assertions.assertSame;
    55import static org.junit.jupiter.api.Assertions.assertTrue;
    66
    7 import org.junit.jupiter.api.extension.RegisterExtension;
     7import java.util.Collections;
     8
    89import org.junit.jupiter.api.Test;
    9 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector.PresetClassification;
    10 import org.openstreetmap.josm.testutils.JOSMTestRules;
    11 
    12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1310
    1411/**
     
    1613 */
    1714class TaggingPresetSelectorTest {
    18 
    1915    /**
    20      * Setup rule
    21      */
    22     @RegisterExtension
    23     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    24     public JOSMTestRules test = new JOSMTestRules();
    25 
    26     /**
    27      * Unit test for {@link PresetClassification#isMatching}.
     16     * Unit test for {@link TaggingPresetSelector.PresetClassifications#getMatchingPresets}.
    2817     */
    2918    @Test
    30     void testIsMatching() {
     19    void testGetMatching() {
    3120        TaggingPreset preset = new TaggingPreset();
    3221        preset.name = "estação de bombeiros"; // fire_station in brazilian portuguese
    33         PresetClassification pc = new PresetClassification(preset);
    34         assertEquals(0, pc.isMatchingName("foo"));
    35         assertTrue(pc.isMatchingName("estação") > 0);
    36         assertTrue(pc.isMatchingName("estacao") > 0);
     22        TaggingPresetSelector.PresetClassifications presetClassifications = new TaggingPresetSelector.PresetClassifications();
     23        presetClassifications.loadPresets(Collections.singleton(preset));
     24        assertTrue(presetClassifications.getMatchingPresets(null, new String[] {"foo"}, false,
     25                false, null, null).isEmpty());
     26        assertSame(preset, presetClassifications.getMatchingPresets(null, new String[] {"estação"}, false,
     27                false, null, null).get(0).preset);
     28        assertSame(preset, presetClassifications.getMatchingPresets(null, new String[] {"estacao"}, false,
     29                false, null, null).get(0).preset);
    3730    }
    3831}
Note: See TracChangeset for help on using the changeset viewer.