diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java index ad96c0b44db2..8158d3d34cfe 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/TestFilesIndex.java @@ -38,7 +38,7 @@ public class TestFilesIndex extends MapReduceIndex { @Nullable Collection getTestDataFor(int testId) throws IOException { ForwardIndex forwardIndex = getForwardIndexMap(); - KeyCollectionForwardIndexAccessor forwardIndexAccessor = (KeyCollectionForwardIndexAccessor)getForwardIndexAccessor(); + KeyCollectionForwardIndexAccessor forwardIndexAccessor = (KeyCollectionForwardIndexAccessor)getForwardIndexAccessor(); return forwardIndexAccessor.deserializeData(forwardIndex.get(testId)); } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingForwardIndexAccessor.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingForwardIndexAccessor.java index d3cbf854301a..be57c5c9296a 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingForwardIndexAccessor.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingForwardIndexAccessor.java @@ -5,6 +5,7 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.ID; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.InputDataDiffBuilder; import com.intellij.util.indexing.impl.forward.AbstractForwardIndexAccessor; import com.intellij.util.io.DataExternalizer; @@ -19,7 +20,7 @@ import java.io.IOException; import java.util.Collections; import java.util.Map; -class StubUpdatingForwardIndexAccessor extends AbstractForwardIndexAccessor { +class StubUpdatingForwardIndexAccessor extends AbstractForwardIndexAccessor { StubUpdatingForwardIndexAccessor() {super(new DataExternalizer() { private volatile boolean myEnsuredStubElementTypesLoaded; @@ -68,10 +69,10 @@ class StubUpdatingForwardIndexAccessor extends AbstractForwardIndexAccessor map, - @Nullable FileContent content) { - return getIndexedStubs(map); + public IndexedStubs convertToDataType(@NotNull InputData data) { + return getIndexedStubs(data.getKeyValues()); } @Override diff --git a/platform/lang-impl/src/com/intellij/util/indexing/HashIdForwardIndexAccessor.java b/platform/lang-impl/src/com/intellij/util/indexing/HashIdForwardIndexAccessor.java index ccad9895626b..0b97d75a0f57 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/HashIdForwardIndexAccessor.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/HashIdForwardIndexAccessor.java @@ -1,6 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.indexing; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.InputDataDiffBuilder; import com.intellij.util.indexing.impl.MapInputDataDiffBuilder; import com.intellij.util.indexing.impl.forward.AbstractMapForwardIndexAccessor; @@ -13,8 +14,8 @@ import java.io.IOException; import java.util.Map; class HashIdForwardIndexAccessor - extends AbstractMapForwardIndexAccessor - implements IntForwardIndexAccessor { + extends AbstractMapForwardIndexAccessor + implements IntForwardIndexAccessor { private final UpdatableSnapshotInputMappingIndex mySnapshotInputMappingIndex; HashIdForwardIndexAccessor(@NotNull UpdatableSnapshotInputMappingIndex snapshotInputMappingIndex) { @@ -35,12 +36,13 @@ class HashIdForwardIndexAccessor } @Override - public int convertToInt(@Nullable Map map, @Nullable Input content) { - try { - return mySnapshotInputMappingIndex.getHashId(content); - } - catch (IOException e) { - throw new RuntimeException(e); - } + public int serializeIndexedDataToInt(@NotNull InputData data) { + return data == InputData.empty() ? 0 : ((HashedInputData)data).getHashId(); + } + + @Nullable + @Override + public Integer convertToDataType(@NotNull InputData data) { + return serializeIndexedDataToInt(data); } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/HashedInputData.java b/platform/lang-impl/src/com/intellij/util/indexing/HashedInputData.java new file mode 100644 index 000000000000..017f4d824268 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/HashedInputData.java @@ -0,0 +1,20 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.util.indexing; + +import com.intellij.util.indexing.impl.InputData; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class HashedInputData extends InputData { + private final int myHashId; + + protected HashedInputData(@NotNull Map values, int hashId) { + super(values); + myHashId = hashId; + } + + public int getHashId() { + return myHashId; + } +} diff --git a/platform/lang-impl/src/com/intellij/util/indexing/SharedMapForwardIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/SharedMapForwardIndex.java index 4264e2da4149..2bad7017ab12 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/SharedMapForwardIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/SharedMapForwardIndex.java @@ -26,10 +26,10 @@ public class SharedMapForwardIndex implements ForwardIndex { // only verification purpose @Nullable - private final AbstractForwardIndexAccessor myAccessor; + private final AbstractForwardIndexAccessor myAccessor; public SharedMapForwardIndex(@NotNull IndexExtension extension, - @Nullable AbstractForwardIndexAccessor accessor, + @Nullable AbstractForwardIndexAccessor accessor, @Nullable File verificationIndexStorageFile, boolean verificationIndexHasChunks) throws IOException { myIndexId = (ID)extension.getName(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappingIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappingIndex.java index a72497ac243a..52c3575e4391 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappingIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappingIndex.java @@ -1,6 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.indexing; +import com.intellij.util.indexing.impl.InputData; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,5 +13,5 @@ import java.util.Map; @ApiStatus.Experimental public interface SnapshotInputMappingIndex extends Closeable { @Nullable - Map readData(@NotNull Input content) throws IOException; + InputData readData(@NotNull Input content) throws IOException; } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappings.java b/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappings.java index 2962d50957ce..e0ebd2ed7634 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappings.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/SnapshotInputMappings.java @@ -13,6 +13,7 @@ import com.intellij.util.CompressionUtil; import com.intellij.util.ExceptionUtil; import com.intellij.util.SystemProperties; import com.intellij.util.indexing.impl.DebugAssertions; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.forward.AbstractForwardIndexAccessor; import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex; import com.intellij.util.io.*; @@ -70,12 +71,13 @@ class SnapshotInputMappings implements UpdatableSnapshotInput @Nullable @Override - public Map readData(@NotNull Input content) throws IOException { + public InputData readData(@NotNull Input content) throws IOException { Map data = null; + int hashId = 0; if (doReadSavedPersistentData) { if (myContents == null || !myContents.isBusyReading() || DebugAssertions.EXTRA_SANITY_CHECKS) { // avoid blocking read, we can calculate index value - int hashId = getHashId(content); + hashId = getHashId(content); ByteArraySequence bytes = readContents(hashId); if (bytes != null) { @@ -96,25 +98,32 @@ class SnapshotInputMappings implements UpdatableSnapshotInput } } } - return data; + return data == null ? null : new HashedInputData<>(data, hashId); } @Override - public void putData(@Nullable Input content, @NotNull Map data) throws IOException { - int hashId = getHashId(content); - boolean saved = savePersistentData(data, hashId); + public InputData putData(@Nullable Input content, @NotNull InputData data) throws IOException { + int hashId; + InputData result; + if (data instanceof HashedInputData) { + hashId = ((HashedInputData)data).getHashId(); + result = data; + } else { + hashId = getHashId(content); + result = hashId == 0 ? InputData.empty() : new HashedInputData<>(data.getKeyValues(), hashId); + } + boolean saved = savePersistentData(data.getKeyValues(), hashId); if (DebugAssertions.EXTRA_SANITY_CHECKS) { if (saved) { try { - myIndexingTrace.put(hashId, getContentDebugData(content) + - "," + - ExceptionUtil.getThrowableText(new Throwable())); + myIndexingTrace.put(hashId, getContentDebugData(content) + "," + ExceptionUtil.getThrowableText(new Throwable())); } catch (IOException ex) { LOG.error(ex); } } } + return result; } @NotNull @@ -123,8 +132,7 @@ class SnapshotInputMappings implements UpdatableSnapshotInput return "[" + content.getFile().getPath() + ";" + content.getFileType().getName() + ";" + content.getCharset() + "]"; } - @Override - public int getHashId(@Nullable Input content) throws IOException { + private int getHashId(@Nullable Input content) throws IOException { return content == null ? 0 : getHashOfContent((FileContent) content); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UpdatableSnapshotInputMappingIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/UpdatableSnapshotInputMappingIndex.java index 26176227537d..b9a467618a98 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UpdatableSnapshotInputMappingIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/UpdatableSnapshotInputMappingIndex.java @@ -1,6 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.indexing; +import com.intellij.util.indexing.impl.InputData; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,9 +14,7 @@ public interface UpdatableSnapshotInputMappingIndex extends S @NotNull Map readData(int hashId) throws IOException; - void putData(@NotNull Input content, @NotNull Map data) throws IOException; - - int getHashId(@Nullable Input content) throws IOException; + InputData putData(@NotNull Input content, @NotNull InputData data) throws IOException; void flush() throws IOException; diff --git a/platform/lang-impl/src/com/intellij/util/indexing/VfsAwareMapReduceIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/VfsAwareMapReduceIndex.java index 13601fb70ff7..a40b0f3abb1f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/VfsAwareMapReduceIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/VfsAwareMapReduceIndex.java @@ -72,7 +72,7 @@ public class VfsAwareMapReduceIndex extends MapReduceIndex extension, @NotNull IndexStorage storage, @Nullable ForwardIndex forwardIndexMap, - @Nullable ForwardIndexAccessor forwardIndexAccessor, + @Nullable ForwardIndexAccessor forwardIndexAccessor, @Nullable SnapshotInputMappingIndex snapshotInputMappings) { super(extension, storage, forwardIndexMap, forwardIndexAccessor, null); SharedIndicesData.registerIndex((ID)myIndexId, extension); @@ -89,10 +89,10 @@ public class VfsAwareMapReduceIndex extends MapReduceIndex mapInput(@Nullable Input content) { - Map data; + protected InputData mapInput(@Nullable Input content) { + InputData data; boolean containsSnapshotData = true; - if (mySnapshotInputMappings != null && !myInMemoryMode.get() && content != null) { + if (mySnapshotInputMappings != null && content != null) { try { data = mySnapshotInputMappings.readData(content); if (data != null) { @@ -108,7 +108,7 @@ public class VfsAwareMapReduceIndex extends MapReduceIndex extends MapReduceIndex data, @Nullable Object forwardIndexData) throws IOException { + protected void updateForwardIndex(int inputId, @NotNull InputData data) throws IOException { if (myInMemoryMode.get()) { synchronized (myInMemoryKeysAndValues) { - myInMemoryKeysAndValues.put(inputId, data); + myInMemoryKeysAndValues.put(inputId, data.getKeyValues()); } } else { - super.updateForwardIndex(inputId, data, forwardIndexData); + super.updateForwardIndex(inputId, data); } } @@ -248,7 +248,7 @@ public class VfsAwareMapReduceIndex extends MapReduceIndex forwardIndexAccessor = (AbstractMapForwardIndexAccessor)getForwardIndexAccessor(); + AbstractMapForwardIndexAccessor forwardIndexAccessor = (AbstractMapForwardIndexAccessor)getForwardIndexAccessor(); return forwardIndexAccessor.convertToInputDataMap(serializedInputData); } // in future we will get rid of forward index for SingleEntryFileBasedIndexExtension @@ -319,7 +319,7 @@ public class VfsAwareMapReduceIndex extends MapReduceIndex ForwardIndexAccessor getForwardIndexAccessor(@NotNull IndexExtension indexExtension) { + private static ForwardIndexAccessor getForwardIndexAccessor(@NotNull IndexExtension indexExtension) { if (!shouldCreateForwardIndex(indexExtension)) return null; return new MapForwardIndexAccessor<>(new InputMapExternalizer<>(indexExtension)); } diff --git a/platform/util/src/com/intellij/util/indexing/impl/InputData.java b/platform/util/src/com/intellij/util/indexing/impl/InputData.java new file mode 100644 index 000000000000..1761f3a44217 --- /dev/null +++ b/platform/util/src/com/intellij/util/indexing/impl/InputData.java @@ -0,0 +1,28 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.util.indexing.impl; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.Map; + +public class InputData { + private static final InputData EMPTY = new InputData<>(Collections.emptyMap()); + + @SuppressWarnings("unchecked") + public static InputData empty() { + return EMPTY; + } + + @NotNull + private final Map myKeyValues; + + protected InputData(@NotNull Map values) { + myKeyValues = values; + } + + @NotNull + public Map getKeyValues() { + return myKeyValues; + } +} diff --git a/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java b/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java index 1db858cf0985..4e3c0c544ade 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java +++ b/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java @@ -56,7 +56,7 @@ public abstract class MapReduceIndex implements InvertedIndex< protected final ForwardIndex myForwardIndex; //new private final com.intellij.util.indexing.impl.forward.ForwardIndex myForwardIndexMap; - private final ForwardIndexAccessor myForwardIndexAccessor; + private final ForwardIndexAccessor myForwardIndexAccessor; private final ReentrantReadWriteLock myLock = createLock(); private final boolean myUseIntForwardIndex; @@ -85,7 +85,7 @@ public abstract class MapReduceIndex implements InvertedIndex< protected MapReduceIndex(@NotNull IndexExtension extension, @NotNull IndexStorage storage, @Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndexMap, - @Nullable ForwardIndexAccessor forwardIndexAccessor, + @Nullable ForwardIndexAccessor forwardIndexAccessor, @Nullable ForwardIndex forwardIndex) { myIndexId = extension.getName(); myExtension = extension; @@ -102,7 +102,7 @@ public abstract class MapReduceIndex implements InvertedIndex< protected MapReduceIndex(@NotNull IndexExtension extension, @NotNull IndexStorage storage, @Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex, - @Nullable ForwardIndexAccessor forwardIndexAccessor) { + @Nullable ForwardIndexAccessor forwardIndexAccessor) { this(extension, storage, forwardIndex, forwardIndexAccessor, null); } @@ -117,7 +117,7 @@ public abstract class MapReduceIndex implements InvertedIndex< return myForwardIndexMap; } - public ForwardIndexAccessor getForwardIndexAccessor() { + public ForwardIndexAccessor getForwardIndexAccessor() { return myForwardIndexAccessor; } @@ -266,26 +266,19 @@ public abstract class MapReduceIndex implements InvertedIndex< @NotNull protected UpdateData calculateUpdateData(final int inputId, @Nullable Input content) { - final Map data = mapInput(content); - Object forwardIndexData; - if (myForwardIndexAccessor != null) { - forwardIndexData = myForwardIndexAccessor.convertToDataType(data, content); - } else { - forwardIndexData = null; - } - return createUpdateData(data, + final InputData data = mapInput(content); + return createUpdateData(data.getKeyValues(), () -> getKeysDiffBuilder(inputId), - () -> updateForwardIndex(inputId, data, forwardIndexData)); + () -> updateForwardIndex(inputId, data)); } - protected void updateForwardIndex(int inputId, @NotNull Map data, @Nullable Object forwardIndexData) throws IOException { - if (myForwardIndex != null) myForwardIndex.putInputData(inputId, data); + protected void updateForwardIndex(int inputId, @NotNull InputData data) throws IOException { + if (myForwardIndex != null) myForwardIndex.putInputData(inputId, data.getKeyValues()); if (myForwardIndexMap != null) { if (myUseIntForwardIndex) { - ((IntForwardIndex)myForwardIndexMap).putInt(inputId, (Integer)forwardIndexData); + ((IntForwardIndex)myForwardIndexMap).putInt(inputId, ((IntForwardIndexAccessor)myForwardIndexAccessor).serializeIndexedDataToInt(data)); } else { - //noinspection unchecked - myForwardIndexMap.put(inputId, ((ForwardIndexAccessor)myForwardIndexAccessor).serializeIndexedData(forwardIndexData)); + myForwardIndexMap.put(inputId, myForwardIndexAccessor.serializeIndexedData(data)); } } } @@ -313,14 +306,14 @@ public abstract class MapReduceIndex implements InvertedIndex< } @NotNull - protected Map mapInput(@Nullable Input content) { + protected InputData mapInput(@Nullable Input content) { if (content == null) { - return Collections.emptyMap(); + return InputData.empty(); } Map data = myIndexer.map(content); checkValuesHaveProperEqualsAndHashCode(data, myIndexId, myValueExternalizer); checkCanceled(); - return data; + return new InputData<>(data); } public abstract void checkCanceled(); diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java index cb57a5b0c829..539b58e161a8 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractForwardIndexAccessor.java @@ -5,6 +5,7 @@ import com.intellij.openapi.util.ThreadLocalCachedByteArray; import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream; import com.intellij.openapi.util.io.ByteArraySequence; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.InputDataDiffBuilder; import com.intellij.util.io.DataExternalizer; import com.intellij.util.io.DataOutputStream; @@ -18,7 +19,7 @@ import java.io.IOException; import java.util.Map; @ApiStatus.Experimental -public abstract class AbstractForwardIndexAccessor implements ForwardIndexAccessor { +public abstract class AbstractForwardIndexAccessor implements ForwardIndexAccessor { @NotNull private final DataExternalizer myDataTypeExternalizer; @@ -40,8 +41,16 @@ public abstract class AbstractForwardIndexAccessor return createDiffBuilder(inputId, deserializeData(sequence)); } + @Nullable + public abstract DataType convertToDataType(@NotNull InputData data); + @Nullable @Override + public ByteArraySequence serializeIndexedData(@NotNull InputData data) throws IOException { + return serializeIndexedData(convertToDataType(data)); + } + + @Nullable public ByteArraySequence serializeIndexedData(@Nullable DataType data) throws IOException { if (data == null) return null; return serializeToByteSeq(data, myDataTypeExternalizer, getBufferInitialSize(data)); diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractMapForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractMapForwardIndexAccessor.java index 8e67ffafdfc0..c09e785d53d0 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractMapForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/AbstractMapForwardIndexAccessor.java @@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.Map; -public abstract class AbstractMapForwardIndexAccessor extends AbstractForwardIndexAccessor { +public abstract class AbstractMapForwardIndexAccessor extends AbstractForwardIndexAccessor { public AbstractMapForwardIndexAccessor(@NotNull DataExternalizer externalizer) { super(externalizer); } diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/ForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/ForwardIndexAccessor.java index cd1368cd51dc..e4b97517f88a 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/ForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/ForwardIndexAccessor.java @@ -2,32 +2,26 @@ package com.intellij.util.indexing.impl.forward; import com.intellij.openapi.util.io.ByteArraySequence; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.InputDataDiffBuilder; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.Map; -/** - * - * @param should not hold strong reference to Input because it may lead to OOMs - */ -public interface ForwardIndexAccessor { +@ApiStatus.Experimental +public interface ForwardIndexAccessor { /** * creates a diff builder for given inputId. */ @NotNull InputDataDiffBuilder getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException; - /** - * convert mapped key-values and input to a data type before it will be serialized - */ - DataType convertToDataType(@Nullable Map map, @Nullable Input content); - /** * serialize indexed data to forward index format. */ @Nullable - ByteArraySequence serializeIndexedData(@Nullable DataType data) throws IOException; + ByteArraySequence serializeIndexedData(@NotNull InputData data) throws IOException; } \ No newline at end of file diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/IntForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/IntForwardIndexAccessor.java index 26501c30133a..e0404ae75ced 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/IntForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/IntForwardIndexAccessor.java @@ -2,6 +2,7 @@ package com.intellij.util.indexing.impl.forward; import com.intellij.openapi.util.io.ByteArraySequence; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.InputDataDiffBuilder; import com.intellij.util.io.EnumeratorIntegerDescriptor; import org.jetbrains.annotations.NotNull; @@ -10,22 +11,17 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.Map; -public interface IntForwardIndexAccessor extends ForwardIndexAccessor { +public interface IntForwardIndexAccessor extends ForwardIndexAccessor { @NotNull @Override default InputDataDiffBuilder getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException { return getDiffBuilderFromInt(inputId, sequence == null ? 0 : AbstractForwardIndexAccessor.deserializeFromByteSeq(sequence, EnumeratorIntegerDescriptor.INSTANCE)); } - @Override - default Integer convertToDataType(@Nullable Map map, @Nullable Input content) { - return convertToInt(map, content); - } - @Nullable @Override - default ByteArraySequence serializeIndexedData(@Nullable Integer data) throws IOException { - return data == null ? null : AbstractForwardIndexAccessor.serializeToByteSeq(data, EnumeratorIntegerDescriptor.INSTANCE, 8); + default ByteArraySequence serializeIndexedData(@NotNull InputData data) throws IOException { + return AbstractForwardIndexAccessor.serializeToByteSeq(serializeIndexedDataToInt(data), EnumeratorIntegerDescriptor.INSTANCE, 8); } /** @@ -34,8 +30,5 @@ public interface IntForwardIndexAccessor extends ForwardIndex @NotNull InputDataDiffBuilder getDiffBuilderFromInt(int inputId, int value) throws IOException; - /** - * convert mapped key-values and input to a data type before it will be serialized - */ - int convertToInt(@Nullable Map map, @Nullable Input content); + int serializeIndexedDataToInt(@NotNull InputData data); } diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/KeyCollectionForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/KeyCollectionForwardIndexAccessor.java index ad3d2b862ede..e66324e782c4 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/KeyCollectionForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/KeyCollectionForwardIndexAccessor.java @@ -5,6 +5,7 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.IndexExtension; import com.intellij.util.indexing.IndexId; import com.intellij.util.indexing.impl.CollectionInputDataDiffBuilder; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.indexing.impl.InputDataDiffBuilder; import com.intellij.util.indexing.impl.InputIndexDataExternalizer; import com.intellij.util.io.DataExternalizer; @@ -13,16 +14,18 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; import java.util.Collection; import java.util.Map; +import java.util.Set; @ApiStatus.Experimental -public class KeyCollectionForwardIndexAccessor extends AbstractForwardIndexAccessor, Input> { +public class KeyCollectionForwardIndexAccessor extends AbstractForwardIndexAccessor> { public KeyCollectionForwardIndexAccessor(@NotNull DataExternalizer> externalizer) { super(externalizer); } - public KeyCollectionForwardIndexAccessor(@NotNull IndexExtension extension) { + public KeyCollectionForwardIndexAccessor(@NotNull IndexExtension extension) { this(extension.getKeyDescriptor(), extension.getName()); } @@ -35,9 +38,11 @@ public class KeyCollectionForwardIndexAccessor extends Abstra return new CollectionInputDataDiffBuilder<>(inputId, keys); } + @Nullable @Override - public Collection convertToDataType(@Nullable Map map, @Nullable Input content) { - return ContainerUtil.isEmpty(map) ? null : map.keySet(); + public Collection convertToDataType(@NotNull InputData data) { + Set keys = data.getKeyValues().keySet(); + return keys.isEmpty() ? null : keys; } @Override diff --git a/platform/util/src/com/intellij/util/indexing/impl/forward/MapForwardIndexAccessor.java b/platform/util/src/com/intellij/util/indexing/impl/forward/MapForwardIndexAccessor.java index fb907c0d3bc2..b15cc162d024 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/forward/MapForwardIndexAccessor.java +++ b/platform/util/src/com/intellij/util/indexing/impl/forward/MapForwardIndexAccessor.java @@ -1,13 +1,15 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.indexing.impl.forward; +import com.intellij.util.indexing.impl.InputData; import com.intellij.util.io.DataExternalizer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; import java.util.Map; -public class MapForwardIndexAccessor extends AbstractMapForwardIndexAccessor, Input> { +public class MapForwardIndexAccessor extends AbstractMapForwardIndexAccessor> { public MapForwardIndexAccessor(@NotNull DataExternalizer> externalizer) { super(externalizer); } @@ -22,9 +24,9 @@ public class MapForwardIndexAccessor extends AbstractMapForwa protected int getBufferInitialSize(@NotNull Map map) { return 4 * map.size(); } - + @Nullable @Override - public Map convertToDataType(@Nullable Map map, @Nullable Input content) { - return map; + public Map convertToDataType(@NotNull InputData data) { + return data.getKeyValues(); } }