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
* the second element.
     * <p>
     * The default implementation of this method is based on
     * comparing the elements' categories as computed by the <code>category</code>
     * framework method. Elements within the same category are further 
     * subjected to a case insensitive compare of their label strings, either
     * as computed by the content viewer's label provider, or their 
     * <code>toString</code> values in other cases. Subclasses may override.
     * </p>
     * 
     * @param viewer the viewer
     * @param e1 the first element
     * @param e2 the second element
     * @return a negative number if the first element is less  than the 
     *  second element; the value <code>0</code> if the first element is
     *  equal to the second element; and a positive number if the first
     *  element is greater than the second element
     */
    public int compare(Viewer viewer, Object e1, Object e2) {
        int cat1 = category(e1);
        int cat2 = category(e2);
        if (cat1 != cat2) {
			return cat1 - cat2;
		}
    	
        String name1;
        String name2;
        if (viewer == null || !(viewer instanceof ContentViewer)) {
            name1 = e1.toString();
            name2 = e2.toString();