diff --git a/core/serialization/serialization.iml b/core/serialization/serialization.iml
index e3ad3ad8c79..1ebc393e8c9 100644
--- a/core/serialization/serialization.iml
+++ b/core/serialization/serialization.iml
@@ -8,7 +8,6 @@
-
diff --git a/core/serialization/src/org/jetbrains/kotlin/serialization/Interner.java b/core/serialization/src/org/jetbrains/kotlin/serialization/Interner.java
index 4ff42614d8a..bad92821b79 100644
--- a/core/serialization/src/org/jetbrains/kotlin/serialization/Interner.java
+++ b/core/serialization/src/org/jetbrains/kotlin/serialization/Interner.java
@@ -16,65 +16,52 @@
package org.jetbrains.kotlin.serialization;
-import gnu.trove.TObjectHashingStrategy;
-import gnu.trove.TObjectIntHashMap;
import kotlin.Function1;
import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public final class Interner {
private final Interner parent;
private final int firstIndex;
- private final TObjectIntHashMap interned;
+ private final Map interned = new HashMap();
- public Interner(Interner parent, @NotNull TObjectHashingStrategy hashing) {
+ public Interner(Interner parent) {
this.parent = parent;
this.firstIndex = parent != null ? parent.interned.size() + parent.firstIndex : 0;
- this.interned = new TObjectIntHashMap(hashing);
- }
-
- public Interner(@NotNull TObjectHashingStrategy hashing) {
- this(null, hashing);
- }
-
- @SuppressWarnings("unchecked")
- public Interner(@Nullable Interner parent) {
- this(parent, TObjectHashingStrategy.CANONICAL);
}
public Interner() {
- this((Interner) null);
+ this(null);
}
- private int find(@NotNull T obj) {
+ @Nullable
+ private Integer find(@NotNull T obj) {
assert parent == null || parent.interned.size() + parent.firstIndex == firstIndex :
"Parent changed in parallel with child: indexes will be wrong";
if (parent != null) {
- int index = parent.find(obj);
- if (index >= 0) return index;
+ Integer index = parent.find(obj);
+ if (index != null) return index;
}
- if (interned.contains(obj)) {
- return interned.get(obj);
- }
- return -1;
+ return interned.get(obj);
}
public int intern(@NotNull T obj) {
- int index = find(obj);
- if (index >= 0) return index;
+ Integer index = find(obj);
+ if (index != null) return index;
index = firstIndex + interned.size();
interned.put(obj, index);
return index;
}
- @SuppressWarnings("unchecked")
@NotNull
public List getAllInternedObjects() {
- return KotlinPackage.toSortedListBy((T[]) interned.keys(), new Function1() {
+ return KotlinPackage.toSortedListBy(interned.keySet(), new Function1() {
@Override
public Integer invoke(T key) {
return interned.get(key);
diff --git a/core/serialization/src/org/jetbrains/kotlin/serialization/StringTable.java b/core/serialization/src/org/jetbrains/kotlin/serialization/StringTable.java
index d02183f6fb3..7590e2fafe7 100644
--- a/core/serialization/src/org/jetbrains/kotlin/serialization/StringTable.java
+++ b/core/serialization/src/org/jetbrains/kotlin/serialization/StringTable.java
@@ -16,7 +16,8 @@
package org.jetbrains.kotlin.serialization;
-import gnu.trove.TObjectHashingStrategy;
+import kotlin.Function1;
+import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor;
@@ -30,27 +31,35 @@ import java.util.List;
import static org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName;
public class StringTable {
- public static final TObjectHashingStrategy QUALIFIED_NAME_BUILDER_HASHING =
- new TObjectHashingStrategy() {
- @Override
- public int computeHashCode(QualifiedName.Builder object) {
- int result = 13;
- result = 31 * result + object.getParentQualifiedName();
- result = 31 * result + object.getShortName();
- result = 31 * result + object.getKind().hashCode();
- return result;
- }
+ private static final class FqNameProto {
+ public final QualifiedName.Builder fqName;
- @Override
- public boolean equals(QualifiedName.Builder o1, QualifiedName.Builder o2) {
- return o1.getParentQualifiedName() == o2.getParentQualifiedName()
- && o1.getShortName() == o2.getShortName()
- && o1.getKind() == o2.getKind();
- }
- };
+ public FqNameProto(@NotNull QualifiedName.Builder fqName) {
+ this.fqName = fqName;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 13;
+ result = 31 * result + fqName.getParentQualifiedName();
+ result = 31 * result + fqName.getShortName();
+ result = 31 * result + fqName.getKind().hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null || getClass() != obj.getClass()) return false;
+
+ QualifiedName.Builder other = ((FqNameProto) obj).fqName;
+ return fqName.getParentQualifiedName() == other.getParentQualifiedName()
+ && fqName.getShortName() == other.getShortName()
+ && fqName.getKind() == other.getKind();
+ }
+ }
private final Interner strings = new Interner();
- private final Interner qualifiedNames = new Interner(QUALIFIED_NAME_BUILDER_HASHING);
+ private final Interner qualifiedNames = new Interner();
@NotNull
public List getStrings() {
@@ -59,7 +68,12 @@ public class StringTable {
@NotNull
public List getFqNames() {
- return qualifiedNames.getAllInternedObjects();
+ return KotlinPackage.map(qualifiedNames.getAllInternedObjects(), new Function1() {
+ @Override
+ public QualifiedName.Builder invoke(FqNameProto proto) {
+ return proto.fqName;
+ }
+ });
}
public int getSimpleNameIndex(@NotNull Name name) {
@@ -92,7 +106,7 @@ public class StringTable {
throw new IllegalStateException("FQ names are only stored for top-level or inner classes: " + descriptor);
}
- return qualifiedNames.intern(builder);
+ return qualifiedNames.intern(new FqNameProto(builder));
}
public int getFqNameIndex(@NotNull FqName fqName) {
@@ -103,7 +117,7 @@ public class StringTable {
if (result != -1) {
builder.setParentQualifiedName(result);
}
- result = qualifiedNames.intern(builder);
+ result = qualifiedNames.intern(new FqNameProto(builder));
}
return result;
}