Bug 70856 [Viewers] ComboViewer internalRefresh is slow
When you call ComboViewer internalRefresh (via StructuredViewer.refresh), the viewer clears the model, gets the list of items from the data model and walks through them one by one, adding them to the combo and the element map: ILabelProvider labelProvider= (ILabelProvider) getLabelProvider(); for (int i= 0; i < children.length; i++) { Object el = children[i]; listAdd(labelProvider.getText(el), i); listMap.add(el); mapElement(el, list); // must map it, since findItem only looks in map, if enabled } However, this is a slow process because listAdd() calls combo.add(), which copies over the current list and adds one item to it. So in my list of 376 items, 376 new Arrays are created, weahc one larger than the last, and 376 arrayCopy's are done and combo.setItems() is callled 376 times, and from my profiling, it looks like a lot of time is spent in setItems. Would it be better to do: ILabelProvider labelProvider= (ILabelProvider) getLabelProvider(); String[] items = new String[children.length]; for (int i= 0; i < children.length; i++) { Object el = children[i]; //listAdd(labelProvider.getText(el), i); item[i] = labelProvider.getText(el); listMap.add(el); mapElement(el, list); // must map it, since findItem only looks in map, if enabled } listSetItems(items); which will call combo.setItems() only once? I have not been able to test this, because of the listMap variable referred to above is private and I can't subclass ComboViewer anyway because it is final.
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java
*/
    protected Widget doFindInputItem(Object element) {
        if (element != null && equals(element, getRoot()))
            return getControl();
        return null;
    }
    /* (non-Javadoc)
     * Method declared on StructuredViewer.
     * Since SWT.List doesn't use items we always return the List itself.
     */
    protected Widget doFindItem(Object element) {
        if (element != null) {
            if (listMap.contains(element))
                return getControl();
        }
        return null;
    }
    /* (non-Javadoc)
     * Method declared on StructuredViewer.
     */
    protected void doUpdateItem(Widget data, Object element, boolean fullMap) {
        if (element != null) {
            int ix = listMap.indexOf(element);
            if (ix >= 0) {
                ILabelProvider labelProvider = (ILabelProvider) getLabelProvider();
                listSetItem(ix, getLabelProviderText(labelProvider,element));
            }
        }
    }
    /* (non-Javadoc)