For 102342 invocations of TreeItem#setImage on Windows: time (ms) unpatched 1923 patched 786 --- Tree.java.original 2008-03-25 19:19:34.419600000 +0200 +++ Tree.java 2008-03-25 19:19:28.808600000 +0200 @@ -3526,13 +3526,19 @@ int imageIndex (Image image, int index) { if (image == null) return OS.I_IMAGENONE; + boolean updateImageList; if (imageList == null) { Rectangle bounds = image.getBounds (); imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height); + updateImageList = true; + } else { + updateImageList = false; } int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) imageIndex = imageList.add (image); - if (hwndHeader == 0 || OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0) == index) { + if (imageIndex == -1) { + imageIndex = imageList.add (image); + } + if (updateImageList && (hwndHeader == 0 || OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0) == index)) { int /*long*/ hImageList = imageList.getHandle (); int /*long*/ hOldImageList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0); if (hOldImageList != hImageList) { --- TreeItem.java.original 2008-03-25 19:19:45.379600000 +0200 +++ TreeItem.java 2008-03-25 19:19:41.316600000 +0200 @@ -1634,7 +1634,14 @@ * @since 3.1 */ public void setImage (Image [] images) { - checkWidget(); + + /* + * It doesn't make sense to checkWidget() here because the method just + * delegates to another method and doesn't use the instance state before + * doing so i.e. if checkWidget() is at all necessary, it will be performed + * by the called method. + */ + // checkWidget(); if (images == null) error (SWT.ERROR_NULL_ARGUMENT); for (int i=0; i