added caching + minor size opts

This commit is contained in:
Maxim.Mossienko
2014-07-13 21:44:34 +02:00
parent 63453c3527
commit b7cea46da2
2 changed files with 34 additions and 4 deletions
@@ -68,7 +68,7 @@ public class BytecodeAnalysisConverter implements ApplicationComponent {
@Override
public Void compute() throws IOException {
myNamesEnumerator = new PersistentStringEnumerator(namesFile, true);
myCompoundKeyEnumerator = new PersistentEnumeratorDelegate<int[]>(compoundKeysFile, new IntArrayKeyDescriptor(), 1024 * 4);
myCompoundKeyEnumerator = new IntArrayPersistentEnumerator(compoundKeysFile, new IntArrayKeyDescriptor());
return null;
}
}, new Runnable() {
@@ -451,4 +451,34 @@ public class BytecodeAnalysisConverter implements ApplicationComponent {
}
}
private static class IntArrayPersistentEnumerator extends PersistentEnumeratorDelegate<int[]> {
private final CachingEnumerator<int[]> myCache;
public IntArrayPersistentEnumerator(File compoundKeysFile, IntArrayKeyDescriptor descriptor) throws IOException {
super(compoundKeysFile, descriptor, 1024 * 4);
myCache = new CachingEnumerator<int[]>(new DataEnumerator<int[]>() {
@Override
public int enumerate(@Nullable int[] value) throws IOException {
return IntArrayPersistentEnumerator.super.enumerate(value);
}
@Nullable
@Override
public int[] valueOf(int idx) throws IOException {
return IntArrayPersistentEnumerator.super.valueOf(idx);
}
}, descriptor);
}
@Override
public int enumerate(@Nullable int[] value) throws IOException {
return myCache.enumerate(value);
}
@Nullable
@Override
public int[] valueOf(int idx) throws IOException {
return myCache.valueOf(idx);
}
}
}
@@ -43,7 +43,7 @@ public class BytecodeAnalysisIndex extends FileBasedIndexExtension<Integer, Coll
private static final DataIndexer<Integer, Collection<IntIdEquation>, FileContent> INDEXER =
new ClassDataIndexer(BytecodeAnalysisConverter.getInstance());
private static final int ourInternalVersion = 1;
private static final int ourInternalVersion = 2;
private static boolean ourEnabled = SystemProperties.getBooleanProperty("idea.enable.bytecode.contract.inference", isEnabledByDefault());
private static boolean isEnabledByDefault() {
@@ -103,7 +103,7 @@ public class BytecodeAnalysisIndex extends FileBasedIndexExtension<Integer, Coll
public static class EquationExternalizer implements DataExternalizer<Collection<IntIdEquation>> {
@Override
public void save(@NotNull DataOutput out, Collection<IntIdEquation> equations) throws IOException {
out.writeInt(equations.size());
DataInputOutputUtil.writeINT(out, equations.size());
for (IntIdEquation equation : equations) {
out.writeInt(equation.id);
@@ -132,7 +132,7 @@ public class BytecodeAnalysisIndex extends FileBasedIndexExtension<Integer, Coll
@Override
public Collection<IntIdEquation> read(@NotNull DataInput in) throws IOException {
int size = in.readInt();
int size = DataInputOutputUtil.readINT(in);
ArrayList<IntIdEquation> result = new ArrayList<IntIdEquation>(size);
for (int x = 0; x < size; x++) {