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


Ignore:
Timestamp:
2016-08-01T23:06:53+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13250 - performance optimization when sorting sorting members of a complex relation (patch by gpetermann_muenchen)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r10680 r10700  
    44import java.util.ArrayList;
    55import java.util.Arrays;
     6import java.util.BitSet;
    67import java.util.Collection;
    78import java.util.Collections;
     
    267268        getSelectionModel().setValueIsAdjusting(true);
    268269        getSelectionModel().clearSelection();
     270        BitSet selected = new BitSet();
    269271        for (int row : selectedRows) {
    270272            row--;
    271             getSelectionModel().addSelectionInterval(row, row);
    272         }
     273            selected.set(row);
     274        }
     275        addToSelectedMembers(selected);
    273276        getSelectionModel().setValueIsAdjusting(false);
    274277        fireMakeMemberVisible(selectedRows[0] - 1);
     
    290293        getSelectionModel().setValueIsAdjusting(true);
    291294        getSelectionModel().clearSelection();
     295        BitSet selected = new BitSet();
    292296        for (int row : selectedRows) {
    293297            row++;
    294             getSelectionModel().addSelectionInterval(row, row);
    295         }
     298            selected.set(row);
     299        }
     300        addToSelectedMembers(selected);
    296301        getSelectionModel().setValueIsAdjusting(false);
    297302        fireMakeMemberVisible(selectedRows[0] + 1);
     
    530535        }
    531536        fireTableDataChanged();
     537        BitSet selected = new BitSet();
    532538        for (int row : idx) {
    533             getSelectionModel().addSelectionInterval(row, row);
    534         }
     539            selected.set(row);
     540        }
     541        addToSelectedMembers(selected);
    535542    }
    536543
     
    616623        getSelectionModel().setValueIsAdjusting(true);
    617624        getSelectionModel().clearSelection();
     625        BitSet selected = new BitSet();
    618626        for (int row : selectedIndices) {
    619             getSelectionModel().addSelectionInterval(row, row);
    620         }
     627            selected.set(row);
     628        }
     629        addToSelectedMembers(selected);
    621630        getSelectionModel().setValueIsAdjusting(false);
    622631        // make the first selected member visible
     
    628637
    629638    /**
    630      * Replies true if the index-th relation members referrs
     639     * Add one or more members indices to the selection.
     640     * Detect groups of consecutive indices.
     641     * Only one costly call of addSelectionInterval is performed for each group
     642
     643     * @param selectedIndices selected indices as a bitset
     644     * @return number of groups
     645     */
     646    private int addToSelectedMembers(BitSet selectedIndices) {
     647        if (selectedIndices == null || selectedIndices.isEmpty()) {
     648            return 0;
     649        }
     650        // select the members
     651        //
     652        int start = selectedIndices.nextSetBit(0);
     653        int end;
     654        int steps = 0;
     655        int last = selectedIndices.length();
     656        while (start >= 0) {
     657            end = selectedIndices.nextClearBit(start);
     658            steps++;
     659            getSelectionModel().addSelectionInterval(start, end-1);
     660            start = selectedIndices.nextSetBit(end);
     661            if (start < 0 || end == last)
     662                break;
     663        }
     664        return steps;
     665    }
     666
     667    /**
     668     * Replies true if the index-th relation members refers
    631669     * to an editable relation, i.e. a relation which is not
    632670     * incomplete.
    633671     *
    634672     * @param index the index
    635      * @return true, if the index-th relation members referrs
     673     * @return true, if the index-th relation members refers
    636674     * to an editable relation, i.e. a relation which is not
    637675     * incomplete
     
    694732        getSelectionModel().setValueIsAdjusting(true);
    695733        getSelectionModel().clearSelection();
     734        BitSet selected = new BitSet();
    696735        for (int i = 0; i < members.size(); i++) {
    697736            RelationMember m = members.get(i);
    698737            if (primitives.contains(m.getMember())) {
    699                 this.getSelectionModel().addSelectionInterval(i, i);
    700             }
    701         }
     738                selected.set(i);
     739            }
     740        }
     741        addToSelectedMembers(selected);
    702742        getSelectionModel().setValueIsAdjusting(false);
    703743        if (!getSelectedIndices().isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.