diff options
author | Julian Honnen | 2019-01-21 12:42:34 +0000 |
---|---|---|
committer | Lars Vogel | 2019-01-22 12:34:29 +0000 |
commit | dfd4a6a8a4482420789fa720aca4923f5c4807a8 (patch) | |
tree | 491966c9369052c57ab44d10ec8be3190dfec15b | |
parent | b0f4cf06e9910cc4967b404df45b2edba390636c (diff) | |
download | rt.equinox.bundles-I20190124-1235.tar.gz rt.equinox.bundles-I20190124-1235.tar.xz rt.equinox.bundles-I20190124-1235.zip |
Bug 543638 - Improved MultiStatus#add performanceY20190130-0010Y20190123-2200I20190129-1800I20190128-1800I20190127-1800I20190126-1800I20190125-1800I20190124-1800I20190124-1235I20190124-0930I20190123-1800I20190122-1800
Changed the internal children array to an ArrayList to improve
performance when adding many children and simplify code.
Change-Id: I98fc3547c3d4866f68e7133532c21b98a6657460
Signed-off-by: Julian Honnen <julian.honnen@vector.com>
3 files changed, 24 insertions, 31 deletions
diff --git a/bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF index 8490b1344..8591f04ae 100644 --- a/bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.common; singleton:=true -Bundle-Version: 3.10.200.qualifier +Bundle-Version: 3.10.300.qualifier Bundle-Localization: plugin Export-Package: org.eclipse.core.internal.boot;x-friends:="org.eclipse.core.resources,org.eclipse.core.runtime.compatibility,org.eclipse.pde.build", org.eclipse.core.internal.runtime;common=split;mandatory:=common; diff --git a/bundles/org.eclipse.equinox.common/pom.xml b/bundles/org.eclipse.equinox.common/pom.xml index 0be09dd6d..b91c9efb8 100644 --- a/bundles/org.eclipse.equinox.common/pom.xml +++ b/bundles/org.eclipse.equinox.common/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.common</artifactId> - <version>3.10.200-SNAPSHOT</version> + <version>3.10.300-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/MultiStatus.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/MultiStatus.java index a1f875fdf..a30c485fa 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/MultiStatus.java +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/MultiStatus.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.runtime; +import java.util.*; + /** * A concrete multi-status implementation, * suitable either for instantiating or subclassing. @@ -24,7 +26,7 @@ public class MultiStatus extends Status { /** List of child statuses. */ - private IStatus[] children; + private final List<IStatus> children = new ArrayList<>(); /** * Creates and returns a new multi-status object with the given children. @@ -40,16 +42,7 @@ public class MultiStatus extends Status { public MultiStatus(String pluginId, int code, IStatus[] newChildren, String message, Throwable exception) { this(pluginId, code, message, exception); Assert.isLegal(newChildren != null); - int maxSeverity = getSeverity(); - for (int i = 0; i < newChildren.length; i++) { - Assert.isLegal(newChildren[i] != null); - int severity = newChildren[i].getSeverity(); - if (severity > maxSeverity) - maxSeverity = severity; - } - this.children = new IStatus[newChildren.length]; - setSeverity(maxSeverity); - System.arraycopy(newChildren, 0, this.children, 0, newChildren.length); + addAllInternal(newChildren); } /** @@ -64,7 +57,6 @@ public class MultiStatus extends Status { */ public MultiStatus(String pluginId, int code, String message, Throwable exception) { super(OK, pluginId, code, message, exception); - children = new IStatus[0]; } /** @@ -74,10 +66,7 @@ public class MultiStatus extends Status { */ public void add(IStatus status) { Assert.isLegal(status != null); - IStatus[] result = new IStatus[children.length + 1]; - System.arraycopy(children, 0, result, 0, children.length); - result[result.length - 1] = status; - children = result; + children.add(status); int newSev = status.getSeverity(); if (newSev > getSeverity()) { setSeverity(newSev); @@ -93,15 +82,24 @@ public class MultiStatus extends Status { */ public void addAll(IStatus status) { Assert.isLegal(status != null); - IStatus[] statuses = status.getChildren(); - for (int i = 0; i < statuses.length; i++) { - add(statuses[i]); + addAllInternal(status.getChildren()); + } + + private void addAllInternal(IStatus[] newChildren) { + int maxSeverity = getSeverity(); + for (IStatus child : newChildren) { + Assert.isLegal(child != null); + int severity = child.getSeverity(); + if (severity > maxSeverity) + maxSeverity = severity; } + this.children.addAll(Arrays.asList(newChildren)); + setSeverity(maxSeverity); } @Override public IStatus[] getChildren() { - return children; + return children.toArray(new IStatus[0]); } @Override @@ -135,15 +133,10 @@ public class MultiStatus extends Status { */ @Override public String toString() { - StringBuffer buf = new StringBuffer(super.toString()); - buf.append(" children=["); //$NON-NLS-1$ - for (int i = 0; i < children.length; i++) { - if (i != 0) { - buf.append(" "); //$NON-NLS-1$ - } - buf.append(children[i].toString()); + StringJoiner joiner = new StringJoiner(" ", super.toString() + " children=[", "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + for (IStatus child : children) { + joiner.add(child.toString()); } - buf.append("]"); //$NON-NLS-1$ - return buf.toString(); + return joiner.toString(); } } |