Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2010-12-03 13:56:28 +0000
committerDJ Houghton2010-12-03 13:56:28 +0000
commit507079f5cacb98aa61515ab005203ea060a81fbf (patch)
treee048974c44d5b4cec34300a2a04bf294d7ac5115 /bundles
parentab24ac0d714449059c1ed1be53ebf3561a1367f8 (diff)
downloadrt.equinox.p2-507079f5cacb98aa61515ab005203ea060a81fbf.tar.gz
rt.equinox.p2-507079f5cacb98aa61515ab005203ea060a81fbf.tar.xz
rt.equinox.p2-507079f5cacb98aa61515ab005203ea060a81fbf.zip
Bug 329385 - [repository] Share StringPool for Composite Repositories
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/StringPool.java73
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java16
2 files changed, 3 insertions, 86 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/StringPool.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/StringPool.java
deleted file mode 100644
index f7ff68cd6..000000000
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/StringPool.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * 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 - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.core;
-
-import java.util.HashMap;
-
-/**
- * A string pool is used for sharing strings in a way that eliminates duplicate
- * equal strings. A string pool instance can be maintained over a long period
- * of time, or used as a temporary structure during a string sharing pass over
- * a data structure.
- * <p>
- * This class is not intended to be subclassed by clients.
- * </p>
- */
-public final class StringPool {
- private int savings;
- private final HashMap<String, String> map = new HashMap<String, String>();
-
- /**
- * Creates a new string pool.
- */
- public StringPool() {
- super();
- }
-
- /**
- * Adds a <code>String</code> to the pool. Returns a <code>String</code>
- * that is equal to the argument but that is unique within this pool.
- * @param string The string to add to the pool
- * @return A string that is equal to the argument.
- */
- public String add(String string) {
- if (string == null)
- return string;
- String result = map.get(string);
- if (result != null) {
- if (result != string)
- savings += 44 + 2 * string.length();
- return result;
- }
- //explicitly copy the string to trim excess baggage
- String trim = new String(string.toCharArray());
- map.put(string, trim);
- return trim;
- }
-
- /**
- * Returns an estimate of the size in bytes that was saved by sharing strings in
- * the pool. In particular, this returns the size of all strings that were added to the
- * pool after an equal string had already been added. This value can be used
- * to estimate the effectiveness of a string sharing operation, in order to
- * determine if or when it should be performed again.
- *
- * In some cases this does not precisely represent the number of bytes that
- * were saved. For example, say the pool already contains string S1. Now
- * string S2, which is equal to S1 but not identical, is added to the pool five
- * times. This method will return the size of string S2 multiplied by the
- * number of times it was added, even though the actual savings in this case
- * is only the size of a single copy of S2.
- */
- public int getSavedStringCount() {
- return savings;
- }
-}
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 bdb23985f..b26843f37 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,7 +16,6 @@ import java.util.StringTokenizer;
import javax.xml.parsers.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.Activator;
-import org.eclipse.equinox.internal.p2.core.StringPool;
import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.metadata.Version;
@@ -44,7 +43,6 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants {
protected MultiStatus status = null; // accumulation of non-fatal errors
protected Locator locator = null; // document locator, if supported by the parser
- protected StringPool stringPool = new StringPool();//used to eliminate string duplication
private IProgressMonitor monitor;
private static ServiceTracker<SAXParserFactory, SAXParserFactory> xmlTracker = null;
@@ -62,14 +60,6 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants {
return (status != null ? status : Status.OK_STATUS);
}
- /**
- * Returns the canonical form of a string. Used to eliminate duplicate equal
- * strings.
- */
- protected String canonicalize(String string) {
- return stringPool == null ? string : stringPool.add(string);
- }
-
public boolean isValidXML() {
return (status == null || !status.matches(IStatus.ERROR | IStatus.CANCEL));
}
@@ -320,7 +310,7 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants {
String[] result = new String[required.length + optional.length];
for (int i = 0; i < attributes.getLength(); i += 1) {
String name = attributes.getLocalName(i);
- String value = canonicalize(attributes.getValue(i).trim());
+ String value = attributes.getValue(i).trim().intern();
int j;
if ((j = indexOf(required, name)) >= 0) {
result[j] = value;
@@ -468,7 +458,7 @@ public abstract class XMLParser extends DefaultHandler implements XMLConstants {
}
protected void processCharacters(String data) {
- this.text = canonicalize(data);
+ this.text = data == null ? null : data.intern();
}
}

Back to the top