Search in sources :

Example 1 with ProjectScopeImpl

use of com.intellij.psi.search.ProjectScopeImpl 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)

Aggregations

ProjectAndLibrariesScope (com.intellij.psi.search.ProjectAndLibrariesScope)1 ProjectScopeImpl (com.intellij.psi.search.ProjectScopeImpl)1 TIntHashSet (gnu.trove.TIntHashSet)1