From 321b6be76eafe8c9f9429d38d22408465d5c6552 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Sat, 11 Apr 2026 10:55:13 +0200 Subject: [PATCH] Avoid Rectangle allocation on every mouse move in CTabFolder Replace item.getBounds().contains(x, y) calls in onMouse() with a static containsPoint() helper that checks CTabItem fields directly, avoiding Rectangle allocation on every MouseMove, MouseDown, and MouseUp event. See https://github.com/eclipse-platform/eclipse.platform.swt/issues/3219 Co-Authored-By: Claude Opus 4.6 --- .../org/eclipse/swt/custom/CTabFolder.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java index 23717891c7b..9d5eacb8dd8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java @@ -1807,6 +1807,13 @@ void onMouseDoubleClick(Event event) { notifyListeners(SWT.DefaultSelection, e); } } +/** + * Returns whether the given point (px, py) is contained within the bounds + * of the given CTabItem, without allocating a Rectangle object. + */ +private static boolean containsPoint(CTabItem item, int px, int py) { + return px >= item.x && py >= item.y && px < item.x + item.width && py < item.y + item.height; +} void onMouse(Event event) { if( isDisposed() ) { return; @@ -1874,16 +1881,16 @@ public void run() { CTabItem item = null; if (single) { if (selectedIndex != -1) { - Rectangle bounds = items[selectedIndex].getBounds(); - if (bounds.contains(x, y)){ - item = items[selectedIndex]; + CTabItem selectedItem = items[selectedIndex]; + if (containsPoint(selectedItem, x, y)){ + item = selectedItem; } } } else { for (CTabItem tabItem : items) { - Rectangle bounds = tabItem.getBounds(); - if (bounds.contains(x, y)){ + if (containsPoint(tabItem, x, y)){ item = tabItem; + break; } } } @@ -1917,7 +1924,7 @@ public void run() { for (int i=0; i