Search in sources :

Example 31 with TIntHashSet

use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.

the class AbstractDataGetter method loadCommitsData.

private void loadCommitsData(@NotNull final TIntIntHashMap commits, @NotNull final Consumer<List<T>> consumer, @Nullable ProgressIndicator indicator) {
    final List<T> result = ContainerUtil.newArrayList();
    final TIntHashSet toLoad = new TIntHashSet();
    long taskNumber = myCurrentTaskIndex++;
    for (int id : commits.keys()) {
        T details = getFromCache(id);
        if (details == null || details instanceof LoadingDetails) {
            toLoad.add(id);
            cacheCommit(id, taskNumber);
        } else {
            result.add(details);
        }
    }
    if (toLoad.isEmpty()) {
        sortCommitsByRow(result, commits);
        consumer.consume(result);
    } else {
        Task.Backgroundable task = new Task.Backgroundable(null, "Loading Selected Details", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {

            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                indicator.checkCanceled();
                try {
                    TIntObjectHashMap<T> map = preLoadCommitData(toLoad);
                    map.forEachValue(value -> {
                        result.add(value);
                        return true;
                    });
                    sortCommitsByRow(result, commits);
                    notifyLoaded();
                } catch (VcsException e) {
                    LOG.error(e);
                }
            }

            @Override
            public void onSuccess() {
                consumer.consume(result);
            }
        };
        if (indicator != null) {
            ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
        } else {
            ProgressManager.getInstance().run(task);
        }
    }
}
Also used : Task(com.intellij.openapi.progress.Task) NotNull(org.jetbrains.annotations.NotNull) TIntHashSet(gnu.trove.TIntHashSet) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException)

Example 32 with TIntHashSet

use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.

the class AbstractDataGetter method runLoadCommitsData.

private void runLoadCommitsData(@NotNull Iterable<Integer> hashes) {
    long taskNumber = myCurrentTaskIndex++;
    TIntIntHashMap commits = getCommitsMap(hashes);
    TIntHashSet toLoad = new TIntHashSet();
    for (int id : commits.keys()) {
        cacheCommit(id, taskNumber);
        toLoad.add(id);
    }
    myLoader.queue(new TaskDescriptor(toLoad));
}
Also used : TIntIntHashMap(gnu.trove.TIntIntHashMap) TIntHashSet(gnu.trove.TIntHashSet)

Example 33 with TIntHashSet

use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.

the class XLineBreakpointManager method updateBreakpoints.

private void updateBreakpoints(@NotNull Document document) {
    Collection<XLineBreakpointImpl> breakpoints = myBreakpoints.getKeysByValue(document);
    if (breakpoints == null) {
        return;
    }
    TIntHashSet lines = new TIntHashSet();
    List<XBreakpoint<?>> toRemove = new SmartList<>();
    for (XLineBreakpointImpl breakpoint : breakpoints) {
        breakpoint.updatePosition();
        if (!breakpoint.isValid() || !lines.add(breakpoint.getLine())) {
            toRemove.add(breakpoint);
        }
    }
    removeBreakpoints(toRemove);
}
Also used : XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) SmartList(com.intellij.util.SmartList) TIntHashSet(gnu.trove.TIntHashSet)

Example 34 with TIntHashSet

use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.

the class PersistentFSImpl method validateEvents.

@NotNull
private static List<VFileEvent> validateEvents(@NotNull List<VFileEvent> events) {
    final List<EventWrapper> deletionEvents = ContainerUtil.newArrayList();
    for (int i = 0, size = events.size(); i < size; i++) {
        final VFileEvent event = events.get(i);
        if (event instanceof VFileDeleteEvent && event.isValid()) {
            deletionEvents.add(new EventWrapper((VFileDeleteEvent) event, i));
        }
    }
    final TIntHashSet invalidIDs;
    if (deletionEvents.isEmpty()) {
        invalidIDs = EmptyIntHashSet.INSTANCE;
    } else {
        ContainerUtil.quickSort(deletionEvents, DEPTH_COMPARATOR);
        invalidIDs = new TIntHashSet(deletionEvents.size());
        final Set<VirtualFile> dirsToBeDeleted = new THashSet<>(deletionEvents.size());
        nextEvent: for (EventWrapper wrapper : deletionEvents) {
            final VirtualFile candidate = wrapper.event.getFile();
            VirtualFile parent = candidate;
            while (parent != null) {
                if (dirsToBeDeleted.contains(parent)) {
                    invalidIDs.add(wrapper.id);
                    continue nextEvent;
                }
                parent = parent.getParent();
            }
            if (candidate.isDirectory()) {
                dirsToBeDeleted.add(candidate);
            }
        }
    }
    final List<VFileEvent> filtered = new ArrayList<>(events.size() - invalidIDs.size());
    for (int i = 0, size = events.size(); i < size; i++) {
        final VFileEvent event = events.get(i);
        if (event.isValid() && !(event instanceof VFileDeleteEvent && invalidIDs.contains(i))) {
            filtered.add(event);
        }
    }
    return filtered;
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) TIntHashSet(gnu.trove.TIntHashSet) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with TIntHashSet

use of gnu.trove.TIntHashSet in project intellij-community by JetBrains.

the class PersistentFSImpl method applyChildrenChangeEvents.

private void applyChildrenChangeEvents(@NotNull VirtualFile parent, @NotNull List<VFileEvent> events) {
    final NewVirtualFileSystem delegate = getDelegate(parent);
    TIntArrayList childrenIdsUpdated = new TIntArrayList();
    final int parentId = getFileId(parent);
    assert parentId != 0;
    TIntHashSet parentChildrenIds = new TIntHashSet(FSRecords.list(parentId));
    boolean hasRemovedChildren = false;
    List<VirtualFile> childrenToBeUpdated = new SmartList<>();
    for (VFileEvent event : events) {
        if (event instanceof VFileCreateEvent) {
            String name = ((VFileCreateEvent) event).getChildName();
            final VirtualFile fake = new FakeVirtualFile(parent, name);
            final FileAttributes attributes = delegate.getAttributes(fake);
            if (attributes != null) {
                final int childId = createAndFillRecord(delegate, fake, parentId, attributes);
                assert parent instanceof VirtualDirectoryImpl : parent;
                final VirtualDirectoryImpl dir = (VirtualDirectoryImpl) parent;
                VirtualFileSystemEntry child = dir.createChild(name, childId, dir.getFileSystem());
                childrenToBeUpdated.add(child);
                childrenIdsUpdated.add(childId);
                parentChildrenIds.add(childId);
            }
        } else if (event instanceof VFileDeleteEvent) {
            VirtualFile file = ((VFileDeleteEvent) event).getFile();
            if (!file.exists()) {
                LOG.error("Deleting a file, which does not exist: " + file.getPath());
                continue;
            }
            hasRemovedChildren = true;
            int id = getFileId(file);
            childrenToBeUpdated.add(file);
            childrenIdsUpdated.add(-id);
            parentChildrenIds.remove(id);
        }
    }
    FSRecords.updateList(parentId, parentChildrenIds.toArray());
    if (hasRemovedChildren)
        clearIdCache();
    VirtualDirectoryImpl parentImpl = (VirtualDirectoryImpl) parent;
    for (int i = 0, len = childrenIdsUpdated.size(); i < len; ++i) {
        final int childId = childrenIdsUpdated.get(i);
        final VirtualFile childFile = childrenToBeUpdated.get(i);
        if (childId > 0) {
            parentImpl.addChild((VirtualFileSystemEntry) childFile);
        } else {
            FSRecords.deleteRecordRecursively(-childId);
            parentImpl.removeChild(childFile);
            invalidateSubtree(childFile);
        }
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) TIntHashSet(gnu.trove.TIntHashSet)

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