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);
}
}
}
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));
}
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);
}
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;
}
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);
}
}
}
Aggregations