optimization: avoid expensive VFS event handling in case when no pointers are registered

GitOrigin-RevId: 4408ede39f9ec9b3eccb62580e131e9bb27b2adc
This commit is contained in:
Alexey Kudravtsev
2023-03-31 02:11:43 +02:00
committed by intellij-monorepo-bot
parent 2bb80c01f1
commit c817843ce8

View File

@@ -558,6 +558,10 @@ public final class VirtualFilePointerManagerImpl extends VirtualFilePointerManag
}
private @NotNull CollectedEvents collectEvents(@NotNull List<? extends VFileEvent> events) {
if (!hasAnyPointers()) {
// e.g., in some VFS stress tests
return new CollectedEvents(new MultiMap<>(), List.of(), List.of(), 0, 0);
}
long start = System.currentTimeMillis();
MultiMap<VirtualFilePointerListener, VirtualFilePointerImpl> toFirePointers = MultiMap.create();
List<NodeToUpdate> toUpdateNodes = new ArrayList<>();
@@ -640,6 +644,10 @@ public final class VirtualFilePointerManagerImpl extends VirtualFilePointerManag
return new CollectedEvents(toFirePointers, toUpdateNodes, eventList, startModCount, prepareElapsedMs);
}
private boolean hasAnyPointers() {
return myLocalRoot.children.length != 0 || myTempRoot.children.length != 0;
}
// converts multi-map with pointers-to-fire into convenient
// - (listener->pointers created with this listener) map for firing individual listeners and
// - allPointersToFire list to fire in bulk via VirtualFilePointerListener.TOPIC