mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ability to specify MapValueType in MapBasedForwardIndex
This commit is contained in:
@@ -21,9 +21,7 @@ import com.intellij.util.indexing.DataIndexer;
|
||||
import com.intellij.util.indexing.IndexExtension;
|
||||
import com.intellij.util.indexing.IndexId;
|
||||
import com.intellij.util.indexing.StorageException;
|
||||
import com.intellij.util.indexing.impl.IndexStorage;
|
||||
import com.intellij.util.indexing.impl.MapBasedForwardIndex;
|
||||
import com.intellij.util.indexing.impl.MapReduceIndex;
|
||||
import com.intellij.util.indexing.impl.*;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
@@ -81,7 +79,7 @@ public class StringIndex {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
myIndex = new MapReduceIndex<String, String, PathContentPair>(extension, storage, new MapBasedForwardIndex<String, String>(extension) {
|
||||
myIndex = new MapReduceIndex<String, String, PathContentPair>(extension, storage, new KeyCollectionBasedForwardIndex<String, String>(extension) {
|
||||
@NotNull
|
||||
@Override
|
||||
public PersistentHashMap<Integer, Collection<String>> createMap() throws IOException {
|
||||
|
||||
+6
-4
@@ -33,8 +33,10 @@ import org.jetbrains.jps.builders.storage.BuildDataCorruptedException;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class CompilerBackwardReferenceIndex {
|
||||
private final static Logger LOG = Logger.getInstance(CompilerBackwardReferenceIndex.class);
|
||||
@@ -232,11 +234,11 @@ public class CompilerBackwardReferenceIndex {
|
||||
throws IOException {
|
||||
super(extension,
|
||||
createIndexStorage(extension.getKeyDescriptor(), extension.getValueExternalizer(), extension.getName(), indexDir, readOnly),
|
||||
readOnly ? null : new MapBasedForwardIndex<Key, Value>(extension) {
|
||||
readOnly ? null : new KeyCollectionBasedForwardIndex<Key, Value>(extension) {
|
||||
@NotNull
|
||||
@Override
|
||||
public PersistentHashMap<Integer, Collection<Key>> createMap() throws IOException {
|
||||
IndexId<Key, Value> id = extension.getName();
|
||||
IndexId<Key, Value> id = getIndexExtension().getName();
|
||||
return new PersistentHashMap<>(new File(indexDir, id.getName() + ".inputs"),
|
||||
EnumeratorIntegerDescriptor.INSTANCE,
|
||||
new InputIndexDataExternalizer<>(extension.getKeyDescriptor(),
|
||||
|
||||
@@ -27,9 +27,9 @@ import java.util.Map;
|
||||
|
||||
class SharedMapBasedForwardIndex<Key, Value> extends AbstractForwardIndex<Key,Value> {
|
||||
private final DataExternalizer<Collection<Key>> mySnapshotIndexExternalizer;
|
||||
private final MapBasedForwardIndex<Key, Value> myUnderlying;
|
||||
private final KeyCollectionBasedForwardIndex<Key, Value> myUnderlying;
|
||||
|
||||
SharedMapBasedForwardIndex(IndexExtension<Key, Value, ?> extension, @Nullable MapBasedForwardIndex<Key, Value> underlying) {
|
||||
SharedMapBasedForwardIndex(IndexExtension<Key, Value, ?> extension, @Nullable KeyCollectionBasedForwardIndex<Key, Value> underlying) {
|
||||
super(extension);
|
||||
myUnderlying = underlying;
|
||||
mySnapshotIndexExternalizer = VfsAwareMapReduceIndex.createInputsIndexExternalizer(extension);
|
||||
@@ -42,7 +42,7 @@ class SharedMapBasedForwardIndex<Key, Value> extends AbstractForwardIndex<Key,Va
|
||||
if (SharedIndicesData.ourFileSharedIndicesEnabled) {
|
||||
Collection<Key> keys = SharedIndicesData.recallFileData(inputId, (ID<Key, ?>)myIndexId, mySnapshotIndexExternalizer);
|
||||
if (myUnderlying != null) {
|
||||
Collection<Key> keysFromInputsIndex = myUnderlying.getInputsIndex().get(inputId);
|
||||
Collection<Key> keysFromInputsIndex = myUnderlying.getInput(inputId);
|
||||
|
||||
if (keys == null && keysFromInputsIndex != null ||
|
||||
!DebugAssertions.equals(keysFromInputsIndex, keys, myKeyDescriptor)
|
||||
@@ -58,14 +58,14 @@ class SharedMapBasedForwardIndex<Key, Value> extends AbstractForwardIndex<Key,Va
|
||||
}
|
||||
return new CollectionInputDataDiffBuilder<>(inputId, keys);
|
||||
}
|
||||
return new CollectionInputDataDiffBuilder<>(inputId, myUnderlying.getInputsIndex().get(inputId));
|
||||
return new CollectionInputDataDiffBuilder<>(inputId, myUnderlying.getInput(inputId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInputData(int inputId, @NotNull Map<Key, Value> data)
|
||||
throws IOException {
|
||||
Collection<Key> keySeq = data.keySet();
|
||||
if (myUnderlying != null) myUnderlying.putData(inputId, keySeq);
|
||||
if (myUnderlying != null) myUnderlying.putInputData(inputId, data);
|
||||
if (SharedIndicesData.ourFileSharedIndicesEnabled) {
|
||||
if (keySeq.isEmpty()) keySeq = null;
|
||||
SharedIndicesData.associateFileData(inputId, (ID<Key, ?>)myIndexId, keySeq, mySnapshotIndexExternalizer);
|
||||
|
||||
@@ -219,12 +219,12 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
IdIndex.ourSnapshotMappingsEnabled;
|
||||
if (hasSnapshotMapping) return null;
|
||||
|
||||
MapBasedForwardIndex<Key, Value> backgroundIndex =
|
||||
KeyCollectionBasedForwardIndex<Key, Value> backgroundIndex =
|
||||
!SharedIndicesData.ourFileSharedIndicesEnabled || SharedIndicesData.DO_CHECKS ? new MyForwardIndex<>(indexExtension) : null;
|
||||
return new SharedMapBasedForwardIndex<>(indexExtension, backgroundIndex);
|
||||
}
|
||||
|
||||
private static class MyForwardIndex<Key, Value> extends MapBasedForwardIndex<Key, Value> {
|
||||
private static class MyForwardIndex<Key, Value> extends KeyCollectionBasedForwardIndex<Key, Value> {
|
||||
protected MyForwardIndex(IndexExtension<Key, Value, ?> indexExtension) throws IOException {
|
||||
super(indexExtension);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.util.indexing.impl;
|
||||
|
||||
import com.intellij.util.indexing.IndexExtension;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class KeyCollectionBasedForwardIndex<Key, Value> extends MapBasedForwardIndex<Key, Value, Collection<Key>> {
|
||||
protected KeyCollectionBasedForwardIndex(IndexExtension<Key, Value, ?> indexExtension) throws IOException {
|
||||
super(indexExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId, Collection<Key> keys) throws IOException {
|
||||
return new CollectionInputDataDiffBuilder<Key, Value>(inputId, keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Key> convertToMapValueType(int inputId, Map<Key, Value> map) throws IOException {
|
||||
return map.keySet();
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class MapBasedForwardIndex<Key, Value> extends AbstractForwardIndex<Key,Value> {
|
||||
public abstract class MapBasedForwardIndex<Key, Value, MapValueType> extends AbstractForwardIndex<Key,Value> {
|
||||
@NotNull
|
||||
private volatile PersistentHashMap<Integer, Collection<Key>> myInputsIndex;
|
||||
private volatile PersistentHashMap<Integer, MapValueType> myInputsIndex;
|
||||
|
||||
protected MapBasedForwardIndex(IndexExtension<Key, Value, ?> indexExtension) throws IOException {
|
||||
super(indexExtension);
|
||||
@@ -35,27 +34,25 @@ public abstract class MapBasedForwardIndex<Key, Value> extends AbstractForwardIn
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract PersistentHashMap<Integer, Collection<Key>> createMap() throws IOException;
|
||||
public abstract PersistentHashMap<Integer, MapValueType> createMap() throws IOException;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InputDataDiffBuilder<Key, Value> getDiffBuilder(final int inputId) throws IOException {
|
||||
return new CollectionInputDataDiffBuilder<Key, Value>(inputId, myInputsIndex.get(inputId));
|
||||
return getDiffBuilder(inputId, getInput(inputId));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PersistentHashMap<Integer, Collection<Key>> getInputsIndex() {
|
||||
return myInputsIndex;
|
||||
protected abstract InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId, MapValueType mapValueType) throws IOException;
|
||||
protected abstract MapValueType convertToMapValueType(int inputId, Map<Key, Value> map) throws IOException;
|
||||
|
||||
public MapValueType getInput(int inputId) throws IOException {
|
||||
return myInputsIndex.get(inputId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInputData(int inputId, @NotNull Map<Key, Value> data) throws IOException {
|
||||
putData(inputId, data.keySet());
|
||||
}
|
||||
|
||||
public void putData(int inputId, Collection<Key> keyCollection) throws IOException {
|
||||
if (keyCollection.size() > 0) {
|
||||
myInputsIndex.put(inputId, keyCollection);
|
||||
if (!data.isEmpty()) {
|
||||
myInputsIndex.put(inputId, convertToMapValueType(inputId, data));
|
||||
}
|
||||
else {
|
||||
myInputsIndex.remove(inputId);
|
||||
|
||||
Reference in New Issue
Block a user