From e67732bc25e88df7e5f492676034e1cd9e9d402c Mon Sep 17 00:00:00 2001 From: Ruslan Cheremin Date: Mon, 23 Sep 2024 15:53:35 +0200 Subject: [PATCH] [cleanup] yak shaving CompactVirtualFileSet GitOrigin-RevId: 7e9ff82dc91dce91e5d3298f5388581df4e31e2f --- .../openapi/vfs/CompactVirtualFileSet.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/CompactVirtualFileSet.java b/platform/core-impl/src/com/intellij/openapi/vfs/CompactVirtualFileSet.java index 6933bf80474a..4eb1c5506274 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/CompactVirtualFileSet.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/CompactVirtualFileSet.java @@ -130,26 +130,28 @@ public final class CompactVirtualFileSet extends AbstractSet implem @Override public boolean add(@NotNull VirtualFile file) { assertNotFrozen(); - boolean added; - if (file instanceof VirtualFileWithId) { - int id = ((VirtualFileWithId)file).getId(); - if (storage != null) { - added = addToStorageWithUpgradeCheck(id); - } - else { - added = weirdFiles.add(file); - if (weirdFiles.size() > INT_SET_LIMIT) { - convertToIntSet(); - } - } + + if (!(file instanceof VirtualFileWithId)) { + return weirdFiles.add(file); } - else { - added = weirdFiles.add(file); + + if (storage == null) { + boolean added = weirdFiles.add(file); + if (weirdFiles.size() > INT_SET_LIMIT) { + convertToIntSet(); + } + return added; } - return added; + + int id = ((VirtualFileWithId)file).getId(); + return addToStorageWithUpgradeCheck(id); } private boolean addToStorageWithUpgradeCheck(int fileId) { + //TODO RC: current design is complicated. + // Simpler approach is to add the fileId directly to the storage, but each storage impl throws an exception + // (~StorageOverflowException) if it can't accommodate this fileId -> the exception is caught and another + // storage impl is chosen then. if (storage instanceof IntSetStorage && storage.shouldUpgradeBeforeAdd(fileId)) { convertToBitSet(); @@ -184,6 +186,7 @@ public final class CompactVirtualFileSet extends AbstractSet implem IntIterator iterator = storage.intIterator(); storage = new PartitionedBitSetStorage(); while (iterator.hasNext()) { + //should be addToStorageWithUpgradeCheck(), but there is nothing to upgrade PartitionedBitSetStorage to storage.add(iterator.nextInt()); } }