Ticket #5631: speed-sort.patch
| File speed-sort.patch, 2.9 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
675 675 * Sorts the current elements in the selection 676 676 */ 677 677 public void sort() { 678 Collections.sort(this.selection, new OsmPrimitiveComparator()); 678 if (this.selection.size()>Main.pref.getInteger("selection.no_sort_above",100000)) return; 679 if (this.selection.size()>Main.pref.getInteger("selection.fast_sort_above",10000)) { 680 Collections.sort(this.selection, new OsmPrimitiveQuickComparator()); 681 } else { 682 Collections.sort(this.selection, new OsmPrimitiveComparator()); 683 } 679 684 } 680 685 681 686 /* ------------------------------------------------------------------------ */ … … 910 915 } 911 916 } 912 917 918 /** Comparator, comparing by type and objects display names */ 913 919 static private class OsmPrimitiveComparator implements Comparator<OsmPrimitive> { 914 920 final private HashMap<OsmPrimitive, String> cache= new HashMap<OsmPrimitive, String>(); 915 921 final private DefaultNameFormatter df = DefaultNameFormatter.getInstance(); … … 940 946 private int compareType(OsmPrimitive a, OsmPrimitive b) { 941 947 // show ways before relations, then nodes 942 948 // 943 if (a.getType().equals(b.getType())) return 0;944 949 if (a.getType().equals(OsmPrimitiveType.WAY)) return -1; 945 950 if (a.getType().equals(OsmPrimitiveType.NODE)) return 1; 946 951 // a is a relation … … 954 959 return compareType(a, b); 955 960 } 956 961 } 962 963 /** Quicker comparator, comparing just by type and ID's */ 964 static private class OsmPrimitiveQuickComparator implements Comparator<OsmPrimitive> { 965 966 private int compareId(OsmPrimitive a, OsmPrimitive b) { 967 long id_a=a.getUniqueId(); 968 long id_b=b.getUniqueId(); 969 if (id_a<id_b) return -1; 970 if (id_a>id_b) return 1; 971 return 0; 972 } 973 974 private int compareType(OsmPrimitive a, OsmPrimitive b) { 975 // show ways before relations, then nodes 976 // 977 if (a.getType().equals(OsmPrimitiveType.WAY)) return -1; 978 if (a.getType().equals(OsmPrimitiveType.NODE)) return 1; 979 // a is a relation 980 if (b.getType().equals(OsmPrimitiveType.WAY)) return 1; 981 // b is a node 982 return -1; 983 } 984 public int compare(OsmPrimitive a, OsmPrimitive b) { 985 if (a.getType().equals(b.getType())) 986 return compareId(a, b); 987 return compareType(a, b); 988 } 989 } 990 957 991 }
