Search in sources :

Example 26 with TIntHashSet

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();
    }
}
Also used : ProjectAndLibrariesScope(com.intellij.psi.search.ProjectAndLibrariesScope) ProjectScopeImpl(com.intellij.psi.search.ProjectScopeImpl) TIntHashSet(gnu.trove.TIntHashSet)

Example 27 with TIntHashSet

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) TIntHashSet(gnu.trove.TIntHashSet) THashSet(gnu.trove.THashSet) TestOnly(org.jetbrains.annotations.TestOnly) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with TIntHashSet

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;");
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) TIntHashSet(gnu.trove.TIntHashSet) PluginException(com.intellij.diagnostic.PluginException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ChooseByNameContributorEx(com.intellij.navigation.ChooseByNameContributorEx) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 29 with TIntHashSet

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);
        }
    }
}
Also used : TIntHashSet(gnu.trove.TIntHashSet)

Example 30 with TIntHashSet

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);
    }
}
Also used : TIntHashSet(gnu.trove.TIntHashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TIntHashSet (gnu.trove.TIntHashSet)50 NotNull (org.jetbrains.annotations.NotNull)16 TIntArrayList (gnu.trove.TIntArrayList)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 IOException (java.io.IOException)4 Nullable (org.jetbrains.annotations.Nullable)4 TIntProcedure (gnu.trove.TIntProcedure)3 ArrayList (java.util.ArrayList)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Processor (com.intellij.util.Processor)2 StorageException (com.intellij.util.indexing.StorageException)2 CharArrayCharSequence (com.intellij.util.text.CharArrayCharSequence)2 THashSet (gnu.trove.THashSet)2 TIntIterator (gnu.trove.TIntIterator)2 LightRef (org.jetbrains.jps.backwardRefs.LightRef)2 GenerateMembersUtil (com.intellij.codeInsight.generation.GenerateMembersUtil)1 Edge (com.intellij.codeInspection.bytecodeAnalysis.asm.ControlFlowGraph.Edge)1 CompilerReferenceFindUsagesTestInfo (com.intellij.compiler.backwardRefs.view.CompilerReferenceFindUsagesTestInfo)1 DirtyScopeTestInfo (com.intellij.compiler.backwardRefs.view.DirtyScopeTestInfo)1 PluginException (com.intellij.diagnostic.PluginException)1