[vcs-log] extract static method in FileBaseIndexImpl to collect inputs for all keys and reuse it in VcsLogFullDetailsIndex

This commit is contained in:
Julia Beliaeva
2016-09-20 00:15:17 +03:00
parent caf61ea196
commit d4bb526d86
2 changed files with 63 additions and 81 deletions
@@ -1044,59 +1044,72 @@ public class FileBasedIndexImpl extends FileBasedIndex {
@NotNull final GlobalSearchScope filter,
@Nullable final Condition<V> valueChecker,
@Nullable final ProjectIndexableFilesFilter projectFilesFilter) {
final ThrowableConvertor<UpdatableIndex<K, V, FileContent>, TIntHashSet, StorageException> convertor =
index -> {
TIntHashSet mainIntersection = null;
for (K dataKey : dataKeys) {
ProgressManager.checkCanceled();
final TIntHashSet copy = new TIntHashSet();
final ValueContainer<V> container = index.getData(dataKey);
for (final ValueContainer.ValueIterator<V> valueIt = container.getValueIterator(); valueIt.hasNext(); ) {
final V value = valueIt.next();
if (valueChecker != null && !valueChecker.value(value)) {
continue;
}
ValueContainer.IntIterator iterator = valueIt.getInputIdsIterator();
if (mainIntersection == null || iterator.size() < mainIntersection.size()) {
while (iterator.hasNext()) {
final int id = iterator.next();
if (mainIntersection == null && (projectFilesFilter == null || projectFilesFilter.containsFileId(id)) ||
mainIntersection != null && mainIntersection.contains(id)
) {
copy.add(id);
}
}
}
else {
mainIntersection.forEach(new TIntProcedure() {
final ValueContainer.IntPredicate predicate = valueIt.getValueAssociationPredicate();
@Override
public boolean execute(int id) {
if (predicate.contains(id)) copy.add(id);
return true;
}
});
}
}
mainIntersection = copy;
if (mainIntersection.isEmpty()) {
return new TIntHashSet();
}
}
return mainIntersection;
};
ThrowableConvertor<UpdatableIndex<K, V, FileContent>, TIntHashSet, StorageException> convertor =
index -> collectInputIdsContainingAllKeys(index, dataKeys, valueChecker,
projectFilesFilter == null ? null : projectFilesFilter::containsFileId);
return processExceptions(indexId, null, filter, convertor);
}
@Nullable
private static <K, V, I> TIntHashSet collectInputIdsContainingAllKeys(@NotNull UpdatableIndex<K, V, I> index,
@NotNull Collection<K> dataKeys,
@Nullable Condition<V> valueChecker,
@Nullable ValueContainer.IntPredicate idChecker)
throws StorageException {
TIntHashSet mainIntersection = null;
for (K dataKey : dataKeys) {
ProgressManager.checkCanceled();
final TIntHashSet copy = new TIntHashSet();
final ValueContainer<V> container = index.getData(dataKey);
for (final ValueContainer.ValueIterator<V> valueIt = container.getValueIterator(); valueIt.hasNext(); ) {
final V value = valueIt.next();
if (valueChecker != null && !valueChecker.value(value)) {
continue;
}
ValueContainer.IntIterator iterator = valueIt.getInputIdsIterator();
if (mainIntersection == null || iterator.size() < mainIntersection.size()) {
while (iterator.hasNext()) {
final int id = iterator.next();
if (mainIntersection == null && (idChecker == null || idChecker.contains(id)) ||
mainIntersection != null && mainIntersection.contains(id)
) {
copy.add(id);
}
}
}
else {
mainIntersection.forEach(new TIntProcedure() {
final ValueContainer.IntPredicate predicate = valueIt.getValueAssociationPredicate();
@Override
public boolean execute(int id) {
if (predicate.contains(id)) copy.add(id);
return true;
}
});
}
}
mainIntersection = copy;
if (mainIntersection.isEmpty()) {
return new TIntHashSet();
}
}
return mainIntersection;
}
@Nullable
public static <K, V, I> TIntHashSet collectInputIdsContainingAllKeys(@NotNull UpdatableIndex<K, V, I> index,
@NotNull Collection<K> dataKeys) throws StorageException {
return collectInputIdsContainingAllKeys(index, dataKeys, null, null);
}
private static boolean processVirtualFiles(@NotNull TIntHashSet ids,
@NotNull final GlobalSearchScope filter,
@NotNull final Processor<VirtualFile> processor) {
@@ -78,38 +78,7 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
@NotNull
public TIntHashSet getCommitsWithAllKeys(@NotNull Collection<Integer> keys) throws StorageException {
TIntHashSet result = null;
for (Integer key : keys) {
TIntHashSet newResult = new TIntHashSet();
ValueContainer<T> data = myMapReduceIndex.getData(key);
ValueContainer.ValueIterator<T> valueIt = data.getValueIterator();
while (valueIt.hasNext()) {
valueIt.next();
ValueContainer.IntIterator inputIt = valueIt.getInputIdsIterator();
if (result != null && result.size() < inputIt.size()) {
ValueContainer.IntPredicate predicate = valueIt.getValueAssociationPredicate();
result.forEach(value -> {
if (predicate.contains(value)) {
newResult.add(value);
}
return true;
});
}
else {
while (inputIt.hasNext()) {
int integer = inputIt.next();
if (result == null || result.contains(integer)) {
newResult.add(integer);
}
}
}
}
result = newResult;
}
TIntHashSet result = FileBasedIndexImpl.collectInputIdsContainingAllKeys(myMapReduceIndex, keys);
if (result == null) return new TIntHashSet();
return result;
}