Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2005-08-29 20:05:02 +0000
committerThomas Watson2005-08-29 20:05:02 +0000
commitea2c3405827c26389ce10f77c4af7db96721de50 (patch)
tree8f1a6821ae37c1071ecffe82619dbf7dc41f766e
parent4c943dfdbd11a083d57aa3eef2df46c1f2ea1562 (diff)
downloadrt.equinox.framework-ea2c3405827c26389ce10f77c4af7db96721de50.tar.gz
rt.equinox.framework-ea2c3405827c26389ce10f77c4af7db96721de50.tar.xz
rt.equinox.framework-ea2c3405827c26389ce10f77c4af7db96721de50.zip
Bug 105017 Performance enhancement for framework.util.Headers
-rw-r--r--bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/framework/util/Headers.java55
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/core/SystemBundleData.java3
2 files changed, 40 insertions, 18 deletions
diff --git a/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/framework/util/Headers.java b/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/framework/util/Headers.java
index d4183e009..302339f68 100644
--- a/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/framework/util/Headers.java
+++ b/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/framework/util/Headers.java
@@ -79,10 +79,13 @@ public class Headers extends Dictionary {
private int getIndex(Object key) {
boolean stringKey = key instanceof String;
for (int i = 0; i < size; i++) {
- if (headers[i].equals(key))
- return i;
- if (stringKey && (headers[i] instanceof String) && ((String) headers[i]).equalsIgnoreCase((String) key))
- return i;
+ if (stringKey && (headers[i] instanceof String)) {
+ if (((String) headers[i]).equalsIgnoreCase((String) key))
+ return i;
+ } else {
+ if (headers[i].equals(key))
+ return i;
+ }
}
return -1;
}
@@ -132,34 +135,56 @@ public class Headers extends Dictionary {
}
/**
- * Set a header value.
+ * Set a header value or optionally replace it if it already exists.
*
* @param key Key name.
* @param value Value of the key or null to remove key.
+ * @param replace A value of true will allow a previous
+ * value of the key to be replaced. A value of false
+ * will cause an IllegalArgumentException to be thrown
+ * if a previous value of the key exists.
* @return the previous value to which the key was mapped,
* or null if the key did not have a previous mapping.
*
* @exception IllegalArgumentException If a case-variant of the key is
* already present.
*/
- public synchronized Object set(Object key, Object value) {
+ public synchronized Object set(Object key, Object value, boolean replace) {
if (key instanceof String)
key = ((String)key).intern();
int i = getIndex(key);
- if (value == null) /* remove */
- {
+ if (value == null) { /* remove */
if (i != -1)
return remove(i);
- } else /* put */
- {
- if (i != -1) /* duplicate key */
- throw new IllegalArgumentException(NLS.bind(Msg.HEADER_DUPLICATE_KEY_EXCEPTION, key));
+ } else { /* put */
+ if (i != -1) { /* duplicate key */
+ if (!replace)
+ throw new IllegalArgumentException(NLS.bind(Msg.HEADER_DUPLICATE_KEY_EXCEPTION, key));
+ Object oldVal = values[i];
+ values[i] = value;
+ return oldVal;
+ }
add(key, value);
}
return null;
}
/**
+ * Set a header value.
+ *
+ * @param key Key name.
+ * @param value Value of the key or null to remove key.
+ * @return the previous value to which the key was mapped,
+ * or null if the key did not have a previous mapping.
+ *
+ * @exception IllegalArgumentException If a case-variant of the key is
+ * already present.
+ */
+ public synchronized Object set(Object key, Object value) {
+ return set(key, value, false);
+ }
+
+ /**
* Returns the number of entries (distinct keys) in this dictionary.
*
* @return the number of keys in this dictionary.
@@ -231,8 +256,7 @@ public class Headers extends Dictionary {
{
if (!firstLine) /* flush last line */
{
- headers.set(header, null); /* remove old attribute,if present */
- headers.set(header, value.toString().trim());
+ headers.set(header, value.toString().trim(), true);
}
break; /* done processing main attributes */
}
@@ -248,8 +272,7 @@ public class Headers extends Dictionary {
}
if (!firstLine) {
- headers.set(header, null); /* remove old attribute,if present */
- headers.set(header, value.toString().trim());
+ headers.set(header, value.toString().trim(), true);
value.setLength(0); /* clear StringBuffer */
}
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/core/SystemBundleData.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/core/SystemBundleData.java
index e69ecd869..dca1294aa 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/core/SystemBundleData.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/core/SystemBundleData.java
@@ -122,8 +122,7 @@ public class SystemBundleData extends AbstractBundleData {
} else {
newValue += "," + append; //$NON-NLS-1$
}
- systemManifest.set(header, null);
- systemManifest.set(header, newValue);
+ systemManifest.set(header, newValue, true);
}
private void createBundleFile(File osgiBase) {

Back to the top