use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class VfsAwareMapIndexStorage method processKeys.
@Override
public boolean processKeys(@NotNull final Processor<Key> processor, GlobalSearchScope scope, final IdFilter idFilter) throws StorageException {
l.lock();
try {
// this will ensure that all new keys are made into the map
myCache.clear();
if (myBuildKeyHashToVirtualFileMapping && idFilter != null) {
TIntHashSet hashMaskSet = null;
long l = System.currentTimeMillis();
File fileWithCaches = getSavedProjectFileValueIds(myLastScannedId, scope);
final boolean useCachedHashIds = ENABLE_CACHED_HASH_IDS && (scope instanceof ProjectScopeImpl || scope instanceof ProjectAndLibrariesScope) && fileWithCaches != null;
int id = myKeyHashToVirtualFileMapping.getCurrentLength();
if (useCachedHashIds && id == myLastScannedId) {
if (ourInvalidatedSessionIds.remove(id) == null) {
try {
hashMaskSet = loadHashedIds(fileWithCaches);
} catch (IOException ignored) {
}
}
}
if (hashMaskSet == null) {
if (useCachedHashIds && myLastScannedId != 0) {
FileUtil.asyncDelete(fileWithCaches);
}
hashMaskSet = new TIntHashSet(1000);
final TIntHashSet finalHashMaskSet = hashMaskSet;
withLock(() -> {
myKeyHashToVirtualFileMapping.force();
ProgressManager.checkCanceled();
myKeyHashToVirtualFileMapping.processAll(key -> {
if (!idFilter.containsFileId(key[1]))
return true;
finalHashMaskSet.add(key[0]);
ProgressManager.checkCanceled();
return true;
}, IntPairInArrayKeyDescriptor.INSTANCE);
});
if (useCachedHashIds) {
saveHashedIds(hashMaskSet, id, scope);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Scanned keyHashToVirtualFileMapping of " + myBaseStorageFile + " for " + (System.currentTimeMillis() - l));
}
final TIntHashSet finalHashMaskSet = hashMaskSet;
return myMap.processKeys(key -> {
if (!finalHashMaskSet.contains(myKeyDescriptor.getHashCode(key)))
return true;
return processor.process(key);
});
}
return myMap.processKeys(processor);
} catch (IOException e) {
throw new StorageException(e);
} catch (RuntimeException e) {
return unwrapCauseAndRethrow(e);
} finally {
l.unlock();
}
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class CompilerReferenceServiceImpl method getReferentFiles.
@TestOnly
@Nullable
public Set<VirtualFile> getReferentFiles(@NotNull PsiElement element) {
FileBasedIndex fileIndex = FileBasedIndex.getInstance();
final TIntHashSet ids = getReferentFileIds(element);
if (ids == null)
return null;
Set<VirtualFile> fileSet = new THashSet<>();
ids.forEach(id -> {
final VirtualFile vFile = fileIndex.findFileById(myProject, id);
assert vFile != null;
fileSet.add(vFile);
return true;
});
return fileSet;
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class ContributorsBasedGotoByModel method processNames.
@Override
public void processNames(final Processor<String> nameProcessor, final boolean checkBoxState) {
long start = System.currentTimeMillis();
List<ChooseByNameContributor> liveContribs = filterDumb(myContributors);
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
Processor<ChooseByNameContributor> processor = new ReadActionProcessor<ChooseByNameContributor>() {
@Override
public boolean processInReadAction(@NotNull ChooseByNameContributor contributor) {
try {
if (!myProject.isDisposed()) {
long contributorStarted = System.currentTimeMillis();
final TIntHashSet filter = new TIntHashSet(1000);
myContributorToItsSymbolsMap.put(contributor, filter);
if (contributor instanceof ChooseByNameContributorEx) {
((ChooseByNameContributorEx) contributor).processNames(s -> {
if (nameProcessor.process(s)) {
filter.add(s.hashCode());
}
return true;
}, FindSymbolParameters.searchScopeFor(myProject, checkBoxState), getIdFilter(checkBoxState));
} else {
String[] names = contributor.getNames(myProject, checkBoxState);
for (String element : names) {
if (nameProcessor.process(element)) {
filter.add(element.hashCode());
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(contributor + " for " + (System.currentTimeMillis() - contributorStarted));
}
}
} catch (ProcessCanceledException | IndexNotReadyException ex) {
// index corruption detected, ignore
} catch (Exception ex) {
LOG.error(ex);
}
return true;
}
};
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(liveContribs, indicator, true, processor)) {
throw new ProcessCanceledException();
}
if (indicator != null) {
indicator.checkCanceled();
}
long finish = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug("processNames(): " + (finish - start) + "ms;");
}
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class ChangeTrackingValueContainer method saveTo.
@Override
public void saveTo(DataOutput out, DataExternalizer<Value> externalizer) throws IOException {
if (needsCompacting()) {
getMergedData().saveTo(out, externalizer);
} else {
final TIntHashSet set = myInvalidated;
if (set != null && set.size() > 0) {
for (int inputId : set.toArray()) {
// mark inputId as invalid, to be processed on load in ValueContainerImpl.readFrom
DataInputOutputUtil.writeINT(out, -inputId);
}
}
final UpdatableValueContainer<Value> toAppend = getAddedDelta();
if (toAppend != null && toAppend.size() > 0) {
toAppend.saveTo(out, externalizer);
}
}
}
use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.
the class PermanentGraphImpl method getContainedInBranchCondition.
@NotNull
@Override
public Condition<CommitId> getContainedInBranchCondition(@NotNull final Collection<CommitId> heads) {
List<Integer> headIds = ContainerUtil.map(heads, new Function<CommitId, Integer>() {
@Override
public Integer fun(CommitId head) {
return myPermanentCommitsInfo.getNodeId(head);
}
});
if (!heads.isEmpty() && ContainerUtil.getFirstItem(heads) instanceof Integer) {
final TIntHashSet branchNodes = new TIntHashSet();
myReachableNodes.walk(headIds, new Consumer<Integer>() {
@Override
public void consume(Integer node) {
branchNodes.add((Integer) myPermanentCommitsInfo.getCommitId(node));
}
});
return new IntContainedInBranchCondition<>(branchNodes);
} else {
final Set<CommitId> branchNodes = ContainerUtil.newHashSet();
myReachableNodes.walk(headIds, new Consumer<Integer>() {
@Override
public void consume(Integer node) {
branchNodes.add(myPermanentCommitsInfo.getCommitId(node));
}
});
return new ContainedInBranchCondition<>(branchNodes);
}
}
Aggregations