From b7cea46da212487e38a3cb8d4e487d66d6ee4974 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Sun, 13 Jul 2014 21:41:21 +0200 Subject: [PATCH] added caching + minor size opts --- .../BytecodeAnalysisConverter.java | 32 ++++++++++++++++++- .../BytecodeAnalysisIndex.java | 6 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisConverter.java b/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisConverter.java index 731b60b243b6..38eaf83dbe2a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisConverter.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisConverter.java @@ -68,7 +68,7 @@ public class BytecodeAnalysisConverter implements ApplicationComponent { @Override public Void compute() throws IOException { myNamesEnumerator = new PersistentStringEnumerator(namesFile, true); - myCompoundKeyEnumerator = new PersistentEnumeratorDelegate(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 { + private final CachingEnumerator myCache; + + public IntArrayPersistentEnumerator(File compoundKeysFile, IntArrayKeyDescriptor descriptor) throws IOException { + super(compoundKeysFile, descriptor, 1024 * 4); + myCache = new CachingEnumerator(new DataEnumerator() { + @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); + } + } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIndex.java b/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIndex.java index 9c93a204123c..a6aa2ac784e3 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIndex.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/bytecodeAnalysis/BytecodeAnalysisIndex.java @@ -43,7 +43,7 @@ public class BytecodeAnalysisIndex extends FileBasedIndexExtension, 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> { @Override public void save(@NotNull DataOutput out, Collection 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 read(@NotNull DataInput in) throws IOException { - int size = in.readInt(); + int size = DataInputOutputUtil.readINT(in); ArrayList result = new ArrayList(size); for (int x = 0; x < size; x++) {