Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 183481 Details for
Bug 329385
[repository] Share StringPool for Composite Repositories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Replace StringPool implementation with String.intern()
stringIntern.txt (text/plain), 5.59 KB, created by
Dean Roberts
on 2010-11-19 11:20:02 EST
(
hide
)
Description:
Replace StringPool implementation with String.intern()
Filename:
MIME Type:
Creator:
Dean Roberts
Created:
2010-11-19 11:20:02 EST
Size:
5.59 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.core >Index: src/org/eclipse/equinox/internal/p2/core/StringPool.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/p2/core/StringPool.java >diff -N src/org/eclipse/equinox/internal/p2/core/StringPool.java >--- src/org/eclipse/equinox/internal/p2/core/StringPool.java 13 Jan 2010 17:20:33 -0000 1.5 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -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; >- } >-} >#P org.eclipse.equinox.p2.repository >Index: src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java,v >retrieving revision 1.10 >diff -u -r1.10 XMLParser.java >--- src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java 4 Oct 2010 16:59:44 -0000 1.10 >+++ src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java 19 Nov 2010 15:56:07 -0000 >@@ -16,7 +16,6 @@ > 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 @@ > 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 @@ > 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 @@ > 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 @@ > } > > protected void processCharacters(String data) { >- this.text = canonicalize(data); >+ this.text = data == null ? null : data.intern(); > } > > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 329385
: 183481