Skip to content

Commit 321b6be

Browse files
vogellaclaude
andcommitted
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 #3219 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 07605c9 commit 321b6be

File tree

1 file changed

+18
-11
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom

1 file changed

+18
-11
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,13 @@ void onMouseDoubleClick(Event event) {
18071807
notifyListeners(SWT.DefaultSelection, e);
18081808
}
18091809
}
1810+
/**
1811+
* Returns whether the given point (px, py) is contained within the bounds
1812+
* of the given CTabItem, without allocating a Rectangle object.
1813+
*/
1814+
private static boolean containsPoint(CTabItem item, int px, int py) {
1815+
return px >= item.x && py >= item.y && px < item.x + item.width && py < item.y + item.height;
1816+
}
18101817
void onMouse(Event event) {
18111818
if( isDisposed() ) {
18121819
return;
@@ -1874,16 +1881,16 @@ public void run() {
18741881
CTabItem item = null;
18751882
if (single) {
18761883
if (selectedIndex != -1) {
1877-
Rectangle bounds = items[selectedIndex].getBounds();
1878-
if (bounds.contains(x, y)){
1879-
item = items[selectedIndex];
1884+
CTabItem selectedItem = items[selectedIndex];
1885+
if (containsPoint(selectedItem, x, y)){
1886+
item = selectedItem;
18801887
}
18811888
}
18821889
} else {
18831890
for (CTabItem tabItem : items) {
1884-
Rectangle bounds = tabItem.getBounds();
1885-
if (bounds.contains(x, y)){
1891+
if (containsPoint(tabItem, x, y)){
18861892
item = tabItem;
1893+
break;
18871894
}
18881895
}
18891896
}
@@ -1917,7 +1924,7 @@ public void run() {
19171924
for (int i=0; i<items.length; i++) {
19181925
CTabItem item = items[i];
19191926
close = false;
1920-
if (item.getBounds().contains(x, y)) {
1927+
if (containsPoint(item, x, y)) {
19211928
close = true;
19221929
if (item.closeRect.contains(x, y)) {
19231930
if (item.closeImageState != SWT.SELECTED && item.closeImageState != SWT.HOT) {
@@ -1955,16 +1962,16 @@ public void run() {
19551962
CTabItem item = null;
19561963
if (single) {
19571964
if (selectedIndex != -1) {
1958-
Rectangle bounds = items[selectedIndex].getBounds();
1959-
if (bounds.contains(x, y)){
1960-
item = items[selectedIndex];
1965+
CTabItem selectedItem = items[selectedIndex];
1966+
if (containsPoint(selectedItem, x, y)){
1967+
item = selectedItem;
19611968
}
19621969
}
19631970
} else {
19641971
for (CTabItem tabItem : items) {
1965-
Rectangle bounds = tabItem.getBounds();
1966-
if (bounds.contains(x, y)){
1972+
if (containsPoint(tabItem, x, y)){
19671973
item = tabItem;
1974+
break;
19681975
}
19691976
}
19701977
}

0 commit comments

Comments
 (0)