use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class PersistentFSImpl method findFileById.
@Nullable
private VirtualFileSystemEntry findFileById(int id, boolean cachedOnly) {
VirtualFileSystemEntry cached = myIdToDirCache.get(id);
if (cached != null)
return cached;
TIntArrayList parents = FSRecords.getParents(id, myIdToDirCache);
// the last element of the parents is either a root or already cached element
int parentId = parents.get(parents.size() - 1);
VirtualFileSystemEntry result = myIdToDirCache.get(parentId);
for (int i = parents.size() - 2; i >= 0; i--) {
if (!(result instanceof VirtualDirectoryImpl)) {
return null;
}
parentId = parents.get(i);
result = ((VirtualDirectoryImpl) result).findChildById(parentId, cachedOnly);
if (result instanceof VirtualDirectoryImpl) {
VirtualFileSystemEntry old = myIdToDirCache.putIfAbsent(parentId, result);
if (old != null)
result = old;
}
}
return result;
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class PersistentFSImpl method persistAllChildren.
@NotNull
private static FSRecords.NameId[] persistAllChildren(@NotNull final VirtualFile file, final int id, @NotNull FSRecords.NameId[] current) {
final NewVirtualFileSystem fs = replaceWithNativeFS(getDelegate(file));
String[] delegateNames = VfsUtil.filterNames(fs.list(file));
if (delegateNames.length == 0 && current.length > 0) {
return current;
}
Set<String> toAdd = ContainerUtil.newHashSet(delegateNames);
for (FSRecords.NameId nameId : current) {
toAdd.remove(nameId.name.toString());
}
final TIntArrayList childrenIds = new TIntArrayList(current.length + toAdd.size());
final List<FSRecords.NameId> nameIds = ContainerUtil.newArrayListWithCapacity(current.length + toAdd.size());
for (FSRecords.NameId nameId : current) {
childrenIds.add(nameId.id);
nameIds.add(nameId);
}
for (String newName : toAdd) {
FakeVirtualFile child = new FakeVirtualFile(file, newName);
FileAttributes attributes = fs.getAttributes(child);
if (attributes != null) {
int childId = createAndFillRecord(fs, child, id, attributes);
childrenIds.add(childId);
nameIds.add(new FSRecords.NameId(childId, FileNameCache.storeName(newName), newName));
}
}
FSRecords.updateList(id, childrenIds.toNativeArray());
setChildrenCached(id);
return nameIds.toArray(new FSRecords.NameId[nameIds.size()]);
}
use of gnu.trove.TIntArrayList 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);
}
}
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class PerFileConfigurableBase method clearSubdirectoriesOnDemandOrCancel.
private int clearSubdirectoriesOnDemandOrCancel(boolean keysToo, Object... keys) {
TIntArrayList rows = new TIntArrayList();
boolean toOverride = false;
for (int i = 0, size = myModel.data.size(); i < size; i++) {
Pair<Object, T> p = myModel.data.get(i);
if (p.first instanceof VirtualFile) {
for (Object key : keys) {
if (key == p.first) {
if (keysToo)
rows.add(-i - 1);
break;
} else if (keyMatches(key, (VirtualFile) p.first, true)) {
toOverride = true;
rows.add(i);
break;
}
}
}
}
int ret = !toOverride ? Messages.NO : askUserToOverrideSubdirectories();
if (ret == Messages.CANCEL)
return ret;
int count = 0;
for (int i : rows.toNativeArray()) {
if (i >= 0 && ret == Messages.NO)
continue;
int index = (i >= 0 ? i : -i - 1) - count;
if (canRemoveTarget(myModel.data.get(index).first)) {
myModel.data.remove(index);
count++;
} else {
myModel.data.set(index, Pair.create(myModel.data.get(0).first, null));
}
}
if (!rows.isEmpty()) {
myModel.fireTableDataChanged();
}
return ret;
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class MergeModelBase method collectAffectedChanges.
/*
* Nearby changes could be affected as well (ex: by moveChangesAfterInsertion)
*
* null means all changes could be affected
*/
@NotNull
@CalledInAwt
private TIntArrayList collectAffectedChanges(@NotNull TIntArrayList directChanges) {
TIntArrayList result = new TIntArrayList(directChanges.size());
int directArrayIndex = 0;
int otherIndex = 0;
while (directArrayIndex < directChanges.size() && otherIndex < getChangesCount()) {
int directIndex = directChanges.get(directArrayIndex);
if (directIndex == otherIndex) {
result.add(directIndex);
otherIndex++;
continue;
}
int directStart = getLineStart(directIndex);
int directEnd = getLineEnd(directIndex);
int otherStart = getLineStart(otherIndex);
int otherEnd = getLineEnd(otherIndex);
if (otherEnd < directStart) {
otherIndex++;
continue;
}
if (otherStart > directEnd) {
directArrayIndex++;
continue;
}
result.add(otherIndex);
otherIndex++;
}
LOG.assertTrue(directChanges.size() <= result.size());
return result;
}
Aggregations