Bug 158020 Lazy initialize ViewerComparator.comparator
20060920 In the ViewerSorter I remember that a performance problem was that that the default constructor called Collator.getInstance() which can be expensive for the first caller. So in JDT we overrode getCollator() to do a lazy initialization. Couldn't this be added to the ViewerComparator by default? In ViewerSorter it wasn't possible as collator was protected. In ViewerComparator this isn't a problem. -> public ViewerComparator(){ this(null); } protected Comparator getComparator() { if (comparator == null) comparator= Policy.getComparator(); return comparator; }
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java
* @param property the property
     * @return <code>true</code> if the sorting would be affected,
     *    and <code>false</code> if it would be unaffected
     */
    public boolean isSorterProperty(Object element, String property) {
        return false;
    }
    /**
     * Sorts the given elements in-place, modifying the given array.
     * <p>
     * The default implementation of this method uses the 
     * java.util.Arrays#sort algorithm on the given array, 
     * calling <code>compare</code> to compare elements.
     * </p>
     * <p>
     * Subclasses may reimplement this method to provide a more optimized implementation.
     * </p>
     *
     * @param viewer the viewer
     * @param elements the elements to sort
     */
    public void sort(final Viewer viewer, Object[] elements) {
        Arrays.sort(elements, new Comparator() {
            public int compare(Object a, Object b) {
                return ViewerComparator.this.compare(viewer, a, b);
            }
        });
    }	
}