Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-04-20 13:18:26 -0400
committerThomas Watson2019-04-20 13:32:15 -0400
commitf4655f59fe493804e8414531b53ae9a193ec1be9 (patch)
treea6b2b7fe80598d85d7c97bc8a83a83da3f329c6b
parente85df6602cc69f644943fd892fe486bc1aa4c2e1 (diff)
downloadrt.equinox.framework-f4655f59fe493804e8414531b53ae9a193ec1be9.tar.gz
rt.equinox.framework-f4655f59fe493804e8414531b53ae9a193ec1be9.tar.xz
rt.equinox.framework-f4655f59fe493804e8414531b53ae9a193ec1be9.zip
Bug 546606 - Optimize population of objectTableI20190422-1800I20190421-1800I20190420-1800
Using an ArrayList here is much faster than populating a large Map keyed by Integer. Change-Id: Ic92bdef9f8d2adeca60d7390cca5d2f0cd19e092 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java46
1 files changed, 28 insertions, 18 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java
index 573fa1f36..6d7cfc4f5 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java
@@ -985,8 +985,17 @@ public class ModuleDatabase {
return (objectTable.size() - 1);
}
- private static void addToReadTable(Object object, int index, Map<Integer, Object> objectTable) {
- objectTable.put(Integer.valueOf(index), object);
+ private static void addToReadTable(Object object, int index, List<Object> objectTable) {
+ if (index == objectTable.size()) {
+ objectTable.add(object);
+ } else if (index < objectTable.size()) {
+ objectTable.set(index, object);
+ } else {
+ while (objectTable.size() < index) {
+ objectTable.add(null);
+ }
+ objectTable.add(object);
+ }
}
public static void store(ModuleDatabase moduleDatabase, DataOutputStream out, boolean persistWirings) throws IOException {
@@ -1139,7 +1148,8 @@ public class ModuleDatabase {
moduleDatabase.nextId.set(in.readLong());
moduleDatabase.setInitialModuleStartLevel(in.readInt());
- Map<Integer, Object> objectTable = new HashMap<>();
+ List<Object> objectTable = new ArrayList<>();
+
if (version >= 2) {
int numStrings = in.readInt();
for (int i = 0; i < numStrings; i++) {
@@ -1235,7 +1245,7 @@ public class ModuleDatabase {
out.writeLong(module.getLastModified());
}
- private static void readModule(ModuleDatabase moduleDatabase, DataInputStream in, Map<Integer, Object> objectTable, int version) throws IOException {
+ private static void readModule(ModuleDatabase moduleDatabase, DataInputStream in, List<Object> objectTable, int version) throws IOException {
ModuleRevisionBuilder builder = new ModuleRevisionBuilder();
int moduleIndex = in.readInt();
String location = readString(in, objectTable);
@@ -1308,7 +1318,7 @@ public class ModuleDatabase {
out.writeInt(requirer);
}
- private static void readWire(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static void readWire(DataInputStream in, List<Object> objectTable) throws IOException {
int wireIndex = in.readInt();
ModuleCapability capability = (ModuleCapability) objectTable.get(in.readInt());
@@ -1373,7 +1383,7 @@ public class ModuleDatabase {
}
}
- private static ModuleWiring readWiring(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static ModuleWiring readWiring(DataInputStream in, List<Object> objectTable) throws IOException {
ModuleRevision revision = (ModuleRevision) objectTable.get(in.readInt());
if (revision == null)
throw new NullPointerException("Could not find revision for wiring."); //$NON-NLS-1$
@@ -1423,7 +1433,7 @@ public class ModuleDatabase {
}
@SuppressWarnings("unchecked")
- private static void readGenericInfo(boolean isCapability, DataInputStream in, ModuleRevisionBuilder builder, Map<Integer, Object> objectTable, int version) throws IOException {
+ private static void readGenericInfo(boolean isCapability, DataInputStream in, ModuleRevisionBuilder builder, List<Object> objectTable, int version) throws IOException {
String namespace = readString(in, objectTable);
Map<String, Object> attributes = version >= 2 ? (Map<String, Object>) objectTable.get(in.readInt()) : readMap(in, objectTable);
Map<String, ?> directives = version >= 2 ? (Map<String, ?>) objectTable.get(in.readInt()) : readMap(in, objectTable);
@@ -1473,12 +1483,12 @@ public class ModuleDatabase {
}
}
- private static void readIndexedMap(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static void readIndexedMap(DataInputStream in, List<Object> objectTable) throws IOException {
Map<String, Object> result = readMap(in, objectTable);
addToReadTable(result, in.readInt(), objectTable);
}
- private static Map<String, Object> readMap(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static Map<String, Object> readMap(DataInputStream in, List<Object> objectTable) throws IOException {
int count = in.readInt();
Map<String, Object> result;
if (count == 0) {
@@ -1501,7 +1511,7 @@ public class ModuleDatabase {
return result;
}
- private static Object readMapValue(DataInputStream in, int type, Map<Integer, Object> objectTable) throws IOException {
+ private static Object readMapValue(DataInputStream in, int type, List<Object> objectTable) throws IOException {
switch (type) {
case VALUE_STRING :
return readString(in, objectTable);
@@ -1569,7 +1579,7 @@ public class ModuleDatabase {
return -2;
}
- private static List<?> readList(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static List<?> readList(DataInputStream in, List<Object> objectTable) throws IOException {
int size = in.readInt();
if (size == 0)
return Collections.emptyList();
@@ -1584,7 +1594,7 @@ public class ModuleDatabase {
return Collections.unmodifiableList(list);
}
- private static Object readListValue(byte listType, DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static Object readListValue(byte listType, DataInputStream in, List<Object> objectTable) throws IOException {
switch (listType) {
case VALUE_STRING :
return readString(in, objectTable);
@@ -1623,17 +1633,17 @@ public class ModuleDatabase {
writeString(string, out, objectTable);
}
- private static Version readIndexedVersion(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static Version readIndexedVersion(DataInputStream in, List<Object> objectTable) throws IOException {
Version version = readVersion0(in, objectTable, false);
addToReadTable(version, in.readInt(), objectTable);
return version;
}
- private static Version readVersion(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ private static Version readVersion(DataInputStream in, List<Object> objectTable) throws IOException {
return readVersion0(in, objectTable, true);
}
- private static Version readVersion0(DataInputStream in, Map<Integer, Object> objectTable, boolean intern) throws IOException {
+ private static Version readVersion0(DataInputStream in, List<Object> objectTable, boolean intern) throws IOException {
byte type = in.readByte();
if (type == INDEX) {
int index = in.readInt();
@@ -1673,17 +1683,17 @@ public class ModuleDatabase {
}
}
- static private String readIndexedString(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ static private String readIndexedString(DataInputStream in, List<Object> objectTable) throws IOException {
String string = readString0(in, objectTable, false);
addToReadTable(string, in.readInt(), objectTable);
return string;
}
- static private String readString(DataInputStream in, Map<Integer, Object> objectTable) throws IOException {
+ static private String readString(DataInputStream in, List<Object> objectTable) throws IOException {
return readString0(in, objectTable, true);
}
- static private String readString0(DataInputStream in, Map<Integer, Object> objectTable, boolean intern) throws IOException {
+ static private String readString0(DataInputStream in, List<Object> objectTable, boolean intern) throws IOException {
byte type = in.readByte();
if (type == INDEX) {
int index = in.readInt();

Back to the top