Skip to content

Commit 9a47563

Browse files
committed
Performance: Cache method calls in loops and optimize string concatenation
Apply low-risk performance optimizations across multiple bundles: Loop optimizations - cache method results: - StyledString: Cache otherRuns.size() before loop - ContributionManager: Cache contributions.size() in indexOf() and duplicate removal - ContentProposalAdapter: Cache autoActivateString.length() in loop - DialogSettings: Cache s.length() before character iteration - MenuManagerShowProcessor: Cache menuModel.getChildren() to avoid repeated calls - WorkbenchPage: Cache getChildren() results to avoid expensive repeated calls String concatenation optimizations: - WizardsRegistryReader: Use StringBuilder for path construction in loop - NewContentTypeDialog: Use StringBuilder for name generation in while loop Repeated expensive calls: - BindingManager: Cache format().length() results in comparison - MenuManagerShowProcessor: Cache getChildren() in loop condition and body All changes are non-API breaking and maintain identical behavior while reducing unnecessary object allocations and method calls.
1 parent 02dabfc commit 9a47563

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerShowProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public void menuAboutToHide(IMenuManager manager) {
123123
* {@link MDynamicMenuContribution} application model elements
124124
*/
125125
private void processDynamicElements(MMenu menuModel, MenuManager menuManager) {
126-
MMenuElement[] menuElements = menuModel.getChildren().toArray(
127-
new MMenuElement[menuModel.getChildren().size()]);
126+
List<MMenuElement> children = menuModel.getChildren();
127+
MMenuElement[] menuElements = children.toArray(new MMenuElement[children.size()]);
128128
for (MMenuElement currentMenuElement : menuElements) {
129129

130130
if (currentMenuElement instanceof MDynamicMenuContribution dmc) {
@@ -154,9 +154,9 @@ private void processDynamicElements(MMenu menuModel, MenuManager menuManager) {
154154
if (mel.size() > 0) {
155155

156156
int position = 0;
157-
while (position < menuModel.getChildren().size()) {
158-
if (currentMenuElement == menuModel.getChildren().get(
159-
position)) {
157+
List<MMenuElement> children = menuModel.getChildren();
158+
while (position < children.size()) {
159+
if (currentMenuElement == children.get(position)) {
160160
position++;
161161
break;
162162
}

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,16 +3423,18 @@ public void resetPerspective() {
34233423
// Hide placeholders for parts that exist in the 'global' areas
34243424
modelService.hideLocalPlaceholders(window, dummyPerspective);
34253425

3426-
int dCount = dummyPerspective.getChildren().size();
3427-
while (!dummyPerspective.getChildren().isEmpty()) {
3428-
MPartSashContainerElement dChild = dummyPerspective.getChildren().remove(0);
3429-
persp.getChildren().add(dChild);
3426+
List<MPartSashContainerElement> dummyChildren = dummyPerspective.getChildren();
3427+
List<MPartSashContainerElement> perspChildren = persp.getChildren();
3428+
int dCount = dummyChildren.size();
3429+
while (!dummyChildren.isEmpty()) {
3430+
MPartSashContainerElement dChild = dummyChildren.remove(0);
3431+
perspChildren.add(dChild);
34303432
}
34313433

3432-
while (persp.getChildren().size() > dCount) {
3433-
MUIElement child = persp.getChildren().get(0);
3434+
while (perspChildren.size() > dCount) {
3435+
MUIElement child = perspChildren.get(0);
34343436
child.setToBeRendered(false);
3435-
persp.getChildren().remove(0);
3437+
perspChildren.remove(0);
34363438
}
34373439

34383440
List<MWindow> existingDetachedWindows = new ArrayList<>();

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/registry/WizardsRegistryReader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ private static class CategoryNode {
7676

7777
CategoryNode(Category cat) {
7878
category = cat;
79-
path = ""; //$NON-NLS-1$
8079
String[] categoryPath = category.getParentPath();
80+
StringBuilder pathBuilder = new StringBuilder();
8181
if (categoryPath != null) {
8282
for (String parentPath : categoryPath) {
83-
path += parentPath + '/';
83+
pathBuilder.append(parentPath).append('/');
8484
}
8585
}
86-
path += cat.getId();
86+
pathBuilder.append(cat.getId());
87+
path = pathBuilder.toString();
8788
}
8889

8990
String getPath() {

0 commit comments

Comments
 (0)