Changeset 14973 in josm


Ignore:
Timestamp:
2019-04-08T10:24:31+02:00 (8 months ago)
Author:
GerdP
Message:

simplify code, improve performance: Remove obsolete method sortErrors()

The sorting was introduced to fix #8517 but is no longer needed since errors are reordered in OsmValidator.getErrorsBySeverityMessageDescription() when the tree is created. The obsolete sort takes much longer and doesn't improve anything.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r14908 r14973  
    4141import org.openstreetmap.josm.data.validation.TestError;
    4242import org.openstreetmap.josm.gui.util.GuiHelper;
    43 import org.openstreetmap.josm.tools.AlphanumComparator;
    4443import org.openstreetmap.josm.tools.Destroyable;
    4544import org.openstreetmap.josm.tools.ListenerList;
    46 import org.openstreetmap.josm.tools.Pair;
    4745
    4846/**
     
    333331
    334332    /**
    335      * Sort list of errors in place (#8517).
    336      */
    337     void sortErrors() {
    338         if (errors.isEmpty())
    339             return;
    340         // Calculate the string to sort only once for each element
    341         // Avoids to call TestError.compare() which is costly
    342         List<Pair<String, TestError>> toSort = new ArrayList<>();
    343         for (int i = 0; i < errors.size(); i++) {
    344             TestError e = errors.get(i);
    345             toSort.add(new Pair<>(e.getNameVisitor().getText(), e));
    346         }
    347         toSort.sort((o1, o2) -> AlphanumComparator.getInstance().compare(o1.a, o2.a));
    348         List<TestError> sortedErrors = new ArrayList<>(errors.size());
    349         for (Pair<String, TestError> p : toSort) {
    350             sortedErrors.add(p.b);
    351         }
    352         errors.clear();
    353         errors.addAll(sortedErrors);
    354     }
    355 
    356     /**
    357333     * Add a new invalidation listener
    358334     * @param listener The listener
     
    379355            return;
    380356        this.errors = errors != null ? errors : new ArrayList<>();
    381         sortErrors();
    382357        if (isVisible()) {
    383358            //TODO: If list is changed because another layer was activated it would be good to store/restore
     
    399374            }
    400375        }
    401         sortErrors();
    402376        if (isVisible()) {
    403377            buildTree();
Note: See TracChangeset for help on using the changeset viewer.