Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blewitt2015-03-10 23:15:29 -0400
committerAlex Blewitt2015-03-11 00:07:21 -0400
commit9fa3ff029333fabef82b1f8dcf3006af9c4d9d01 (patch)
tree84297c2559ac04d0a2c6107bc8f5e30b7694fa23
parent97c049de6141ed78adc45f6083aeb9ff447bfd0c (diff)
downloadrt.equinox.p2-I20150316-0800.tar.gz
rt.equinox.p2-I20150316-0800.tar.xz
rt.equinox.p2-I20150316-0800.zip
To minimise the impact of GC sweeps during repository parsing, store a cache of URIs against the String location against the XML parser. Change-Id: I9f4c0456c2c798cd031011340d386540dc5c9161 Signed-off-by: Alex Blewitt <alex.blewitt@gmail.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java19
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java21
2 files changed, 37 insertions, 3 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java
index 01aa1a396..a22475d63 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java
@@ -4,15 +4,14 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.persistence;
import java.net.*;
-import java.util.List;
-import java.util.StringTokenizer;
+import java.util.*;
import javax.xml.parsers.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.Activator;
@@ -46,6 +45,9 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants {
private IProgressMonitor monitor;
+ // Store a cache of previously seen URIs to avoid GC presure
+ final Map<String, URI> uris = new HashMap<String, URI>();
+
private static ServiceTracker<SAXParserFactory, SAXParserFactory> xmlTracker = null;
public XMLParser(BundleContext context, String pluginId) {
@@ -270,6 +272,17 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants {
*/
protected URI parseURIAttribute(Attributes attributes, boolean required) {
String location = parseOptionalAttribute(attributes, URI_ATTRIBUTE);
+ URI uri = location == null ? null : XMLParser.this.uris.get(location);
+ if (uri == null) {
+ uri = constructURI(attributes, required, location);
+ if (uri != null) {
+ XMLParser.this.uris.put(location, uri);
+ }
+ }
+ return uri;
+ }
+
+ private URI constructURI(Attributes attributes, boolean required, String location) {
try {
if (location != null)
return new URI(location);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java
index 521aee495..50c689d58 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/LocalMetadataRepositoryTest.java
@@ -14,6 +14,7 @@ package org.eclipse.equinox.p2.tests.metadata.repository;
import java.io.File;
import java.net.URI;
import java.util.*;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.*;
import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent;
import org.eclipse.equinox.p2.core.ProvisionException;
@@ -255,4 +256,24 @@ public class LocalMetadataRepositoryTest extends AbstractProvisioningTest {
getEventBus().removeListener(listener);
}
}
+
+ public void testUniqueURIs() throws ProvisionException, OperationCanceledException {
+ // The test data bug 278668 has multiple installable units with the same license uri
+ IMetadataRepository repo = getMetadataRepositoryManager().loadRepository(getTestData("test data bug 278668", "testData/bug278668").toURI(), null);
+ IQueryResult<IInstallableUnit> units = repo.query(QueryUtil.ALL_UNITS, null);
+ URI last = null;
+ Iterator<IInstallableUnit> it = units.iterator();
+ while (it.hasNext()) {
+ IInstallableUnit iu = it.next();
+ Collection<ILicense> licenses = iu.getLicenses();
+ for (ILicense license : licenses) {
+ URI uri = license.getLocation();
+ if (last == null) {
+ last = uri;
+ } else {
+ assertSame("License URIs must be the same object", last, uri);
+ }
+ }
+ }
+ }
}

Back to the top