From d4bb526d867cd3402e5183306285404e8880eb16 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 13 Sep 2016 00:36:29 +0300 Subject: [PATCH] [vcs-log] extract static method in FileBaseIndexImpl to collect inputs for all keys and reuse it in VcsLogFullDetailsIndex --- .../util/indexing/FileBasedIndexImpl.java | 111 ++++++++++-------- .../data/index/VcsLogFullDetailsIndex.java | 33 +----- 2 files changed, 63 insertions(+), 81 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index 2a2561b62580..44a039d595a3 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1044,59 +1044,72 @@ public class FileBasedIndexImpl extends FileBasedIndex { @NotNull final GlobalSearchScope filter, @Nullable final Condition valueChecker, @Nullable final ProjectIndexableFilesFilter projectFilesFilter) { - final ThrowableConvertor, TIntHashSet, StorageException> convertor = - index -> { - TIntHashSet mainIntersection = null; - - for (K dataKey : dataKeys) { - ProgressManager.checkCanceled(); - final TIntHashSet copy = new TIntHashSet(); - final ValueContainer container = index.getData(dataKey); - - for (final ValueContainer.ValueIterator 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, TIntHashSet, StorageException> convertor = + index -> collectInputIdsContainingAllKeys(index, dataKeys, valueChecker, + projectFilesFilter == null ? null : projectFilesFilter::containsFileId); return processExceptions(indexId, null, filter, convertor); } + @Nullable + private static TIntHashSet collectInputIdsContainingAllKeys(@NotNull UpdatableIndex index, + @NotNull Collection dataKeys, + @Nullable Condition valueChecker, + @Nullable ValueContainer.IntPredicate idChecker) + throws StorageException { + TIntHashSet mainIntersection = null; + + for (K dataKey : dataKeys) { + ProgressManager.checkCanceled(); + final TIntHashSet copy = new TIntHashSet(); + final ValueContainer container = index.getData(dataKey); + + for (final ValueContainer.ValueIterator 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 TIntHashSet collectInputIdsContainingAllKeys(@NotNull UpdatableIndex index, + @NotNull Collection dataKeys) throws StorageException { + return collectInputIdsContainingAllKeys(index, dataKeys, null, null); + } + private static boolean processVirtualFiles(@NotNull TIntHashSet ids, @NotNull final GlobalSearchScope filter, @NotNull final Processor processor) { diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java index 4a5ed510313b..589ef5bc475d 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java @@ -78,38 +78,7 @@ public class VcsLogFullDetailsIndex implements Disposable { @NotNull public TIntHashSet getCommitsWithAllKeys(@NotNull Collection keys) throws StorageException { - TIntHashSet result = null; - - for (Integer key : keys) { - TIntHashSet newResult = new TIntHashSet(); - ValueContainer data = myMapReduceIndex.getData(key); - - ValueContainer.ValueIterator 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; }