Skip to content

Commit cca3313

Browse files
committed
Bug 576729 - Reduce NO-OPs for setImage
Removes hotspots in .setImage Especially for the hot ToolItem.set* (Disabled, Hot) Requires same (cached) image instances on repeated calls. Change-Id: If8e470a6ed44608d4e0b4a342f62588acdecc1a2 Signed-off-by: Joerg Kubitz <[email protected]> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/186087 Tested-by: Lars Vogel <[email protected]> Tested-by: Platform Bot <[email protected]> Reviewed-by: Lars Vogel <[email protected]>
1 parent 2d9f240 commit cca3313

File tree

7 files changed

+13
-0
lines changed

7 files changed

+13
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ public void setID (int id) {
704704
@Override
705705
public void setImage (Image image) {
706706
checkWidget ();
707+
if (this.image == image) return;
707708
if ((style & SWT.SEPARATOR) != 0) return;
708709
super.setImage (image);
709710
nsItem.setImage(image != null? image.handle : null);

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ public void setEnabled (boolean enabled) {
10581058
*/
10591059
public void setDisabledImage (Image image) {
10601060
checkWidget();
1061+
if (this.disabledImage == image) return;
10611062
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
10621063
if ((style & SWT.SEPARATOR) != 0) return;
10631064
disabledImage = image;
@@ -1093,6 +1094,7 @@ boolean setFocus () {
10931094
*/
10941095
public void setHotImage (Image image) {
10951096
checkWidget();
1097+
if (this.hotImage == image) return;
10961098
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
10971099
if ((style & SWT.SEPARATOR) != 0) return;
10981100
hotImage = image;
@@ -1102,6 +1104,7 @@ public void setHotImage (Image image) {
11021104
@Override
11031105
public void setImage (Image image) {
11041106
checkWidget();
1107+
if (this.image == image) return;
11051108
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
11061109
if ((style & SWT.SEPARATOR) != 0) return;
11071110
super.setImage (image);

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void releaseWidget () {
176176
*/
177177
public void setImage (Image image) {
178178
checkWidget ();
179+
if (this.image == image) return;
179180
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
180181
this.image = image;
181182
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ public void setImage (Image image) {
10431043
if (GTK.GTK4) return;
10441044

10451045
checkWidget();
1046+
if (this.image == image) return;
10461047
if ((style & SWT.SEPARATOR) != 0) return;
10471048
disposeDefaultDisabledImage();
10481049
super.setImage (image);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ public void setControl (Control control) {
11061106
*/
11071107
public void setDisabledImage (Image image) {
11081108
checkWidget();
1109+
if (this.disabledImage == image) return;
11091110
if ((style & SWT.SEPARATOR) != 0) return;
11101111
disabledImage = image;
11111112
if (image != null) {
@@ -1223,6 +1224,7 @@ void setForegroundRGBA (long handle, GdkRGBA rgba) {
12231224
*/
12241225
public void setHotImage (Image image) {
12251226
checkWidget();
1227+
if (this.hotImage == image) return;
12261228
if ((style & SWT.SEPARATOR) != 0) return;
12271229
hotImage = image;
12281230
if (image != null) {
@@ -1240,6 +1242,7 @@ public void setHotImage (Image image) {
12401242
@Override
12411243
public void setImage (Image image) {
12421244
checkWidget();
1245+
if (this.image == image) return;
12431246
if ((style & SWT.SEPARATOR) != 0) return;
12441247
super.setImage (image);
12451248
disposeDefault();

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ public void setID (int id) {
783783
@Override
784784
public void setImage (Image image) {
785785
checkWidget ();
786+
if (this.image == image) return;
786787
if ((style & SWT.SEPARATOR) != 0) return;
787788
super.setImage (image);
788789
MENUITEMINFO info = new MENUITEMINFO ();

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ public void setEnabled (boolean enabled) {
704704
*/
705705
public void setDisabledImage (Image image) {
706706
checkWidget();
707+
if (this.disabledImage == image) return;
707708
if ((style & SWT.SEPARATOR) != 0) return;
708709
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
709710
parent.layout(isImageSizeChanged(disabledImage, image));
@@ -730,6 +731,7 @@ public void setDisabledImage (Image image) {
730731
*/
731732
public void setHotImage (Image image) {
732733
checkWidget();
734+
if (this.hotImage == image) return;
733735
if ((style & SWT.SEPARATOR) != 0) return;
734736
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
735737
parent.layout(isImageSizeChanged(hotImage, image));
@@ -740,6 +742,7 @@ public void setHotImage (Image image) {
740742
@Override
741743
public void setImage (Image image) {
742744
checkWidget();
745+
if (this.image == image) return;
743746
if ((style & SWT.SEPARATOR) != 0) return;
744747
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
745748
parent.layout(isImageSizeChanged(super.image, image));

0 commit comments

Comments
 (0)