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
} else {
            IBaseLabelProvider prov = ((ContentViewer) viewer)
                    .getLabelProvider();
            if (prov instanceof ILabelProvider) {
                ILabelProvider lprov = (ILabelProvider) prov;
                name1 = lprov.getText(e1);
                name2 = lprov.getText(e2);
            } else {
                name1 = e1.toString();
                name2 = e2.toString();
            }
        }
        if (name1 == null) {
			name1 = "";
		}
        if (name2 == null) {
			name2 = "";
		}
        
        return getComparator().compare(name1, name2);
    }
    /**
     * Returns whether this viewer sorter would be affected 
     * by a change to the given property of the given element.
     * <p>
     * The default implementation of this method returns <code>false</code>.
     * Subclasses may reimplement.
     * </p>
     *
     * @param element the element