mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
VFS isIgnored micro-optimizations
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.fileTypes.impl;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.fileTypes.FileNameMatcherFactory;
|
||||
|
||||
@@ -53,14 +54,14 @@ public class IgnoredPatternSet {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIgnored(@NotNull String fileName) {
|
||||
public boolean isIgnored(@NotNull CharSequence fileName) {
|
||||
if (myIgnorePatterns.findAssociatedFileType(fileName) == Boolean.TRUE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Quite a hack, but still we need to have some name, which
|
||||
//won't be caught by VFS for sure.
|
||||
return fileName.endsWith(FileUtil.ASYNC_DELETE_EXTENSION);
|
||||
return StringUtil.endsWith(fileName, FileUtil.ASYNC_DELETE_EXTENSION);
|
||||
}
|
||||
|
||||
void clearPatterns() {
|
||||
|
||||
+12
-34
@@ -23,8 +23,6 @@ import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent;
|
||||
import com.intellij.util.containers.ConcurrentBitSet;
|
||||
import com.intellij.util.containers.ConcurrentIntObjectMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -33,11 +31,10 @@ import java.util.List;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class IgnoredFileCache {
|
||||
private final ConcurrentBitSet myCheckedIds = new ConcurrentBitSet();
|
||||
private final ConcurrentIntObjectMap<Object> myIgnoredIds = ContainerUtil.createConcurrentIntObjectMap();
|
||||
final class IgnoredFileCache {
|
||||
private final ConcurrentBitSet myNonIgnoredIds = new ConcurrentBitSet();
|
||||
private final IgnoredPatternSet myIgnoredPatterns;
|
||||
private volatile int myVfsEventNesting;
|
||||
private int myVfsEventNesting;
|
||||
|
||||
IgnoredFileCache(@NotNull IgnoredPatternSet ignoredPatterns) {
|
||||
myIgnoredPatterns = ignoredPatterns;
|
||||
@@ -62,8 +59,7 @@ class IgnoredFileCache {
|
||||
if (file instanceof NewVirtualFile && event instanceof VFilePropertyChangeEvent) {
|
||||
int id = ((NewVirtualFile)file).getId();
|
||||
if (id >= 0) {
|
||||
myCheckedIds.clear(id);
|
||||
myIgnoredIds.remove(id);
|
||||
myNonIgnoredIds.clear(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,37 +68,19 @@ class IgnoredFileCache {
|
||||
}
|
||||
|
||||
void clearCache() {
|
||||
myCheckedIds.clear();
|
||||
myIgnoredIds.clear();
|
||||
myNonIgnoredIds.clear();
|
||||
}
|
||||
|
||||
boolean isFileIgnored(@NotNull VirtualFile file) {
|
||||
if (myVfsEventNesting != 0 || !(file instanceof NewVirtualFile)) {
|
||||
return isFileIgnoredNoCache(file);
|
||||
boolean isFileIgnored(VirtualFile file) {
|
||||
int id = myVfsEventNesting == 0 && file instanceof NewVirtualFile ? ((NewVirtualFile)file).getId() : -1;
|
||||
if (id > 0 && myNonIgnoredIds.get(id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = ((NewVirtualFile)file).getId();
|
||||
if (id < 0) {
|
||||
return isFileIgnoredNoCache(file);
|
||||
boolean result = myIgnoredPatterns.isIgnored(file.getNameSequence());
|
||||
if (!result && id > 0) {
|
||||
myNonIgnoredIds.set(id);
|
||||
}
|
||||
|
||||
ConcurrentBitSet checkedIds = myCheckedIds;
|
||||
if (checkedIds.get(id)) {
|
||||
return myIgnoredIds.containsKey(id);
|
||||
}
|
||||
|
||||
boolean result = isFileIgnoredNoCache(file);
|
||||
if (result) {
|
||||
myIgnoredIds.put(id, Boolean.TRUE);
|
||||
}
|
||||
else {
|
||||
myIgnoredIds.remove(id);
|
||||
}
|
||||
checkedIds.set(id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isFileIgnoredNoCache(@NotNull VirtualFile file) {
|
||||
return myIgnoredPatterns.isIgnored(file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
@@ -50,6 +49,7 @@ public class RootIndex {
|
||||
};
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.RootIndex");
|
||||
private static final FileTypeRegistry ourFileTypes = FileTypeRegistry.getInstance();
|
||||
|
||||
private final Map<VirtualFile, String> myPackagePrefixByRoot = ContainerUtil.newHashMap();
|
||||
|
||||
@@ -375,7 +375,7 @@ public class RootIndex {
|
||||
if (info != null) {
|
||||
return info;
|
||||
}
|
||||
if (isIgnored(file)) {
|
||||
if (ourFileTypes.isFileIgnored(file)) {
|
||||
return NonProjectDirectoryInfo.IGNORED;
|
||||
}
|
||||
dir = file.getParent();
|
||||
@@ -397,7 +397,7 @@ public class RootIndex {
|
||||
return info;
|
||||
}
|
||||
|
||||
if (isIgnored(root)) {
|
||||
if (ourFileTypes.isFileIgnored(root)) {
|
||||
return cacheInfos(dir, root, NonProjectDirectoryInfo.IGNORED);
|
||||
}
|
||||
}
|
||||
@@ -433,7 +433,7 @@ public class RootIndex {
|
||||
@Nullable
|
||||
public String getPackageName(@NotNull final VirtualFile dir) {
|
||||
if (dir.isDirectory()) {
|
||||
if (isIgnored(dir)) {
|
||||
if (ourFileTypes.isFileIgnored(dir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ public class RootIndex {
|
||||
boolean hasContentRoots = false;
|
||||
while (dir != null) {
|
||||
hasContentRoots |= info.contentRootOf.get(dir) != null;
|
||||
if (!hasContentRoots && isIgnored(dir)) {
|
||||
if (!hasContentRoots && ourFileTypes.isFileIgnored(dir)) {
|
||||
return null;
|
||||
}
|
||||
if (allRoots.contains(dir)) {
|
||||
@@ -488,10 +488,6 @@ public class RootIndex {
|
||||
return hierarchy;
|
||||
}
|
||||
|
||||
private static boolean isIgnored(@NotNull VirtualFile dir) {
|
||||
return FileTypeRegistry.getInstance().isFileIgnored(dir);
|
||||
}
|
||||
|
||||
private static class RootInfo {
|
||||
// getDirectoriesByPackageName used to be in this order, some clients might rely on that
|
||||
@NotNull final LinkedHashSet<VirtualFile> classAndSourceRoots = ContainerUtil.newLinkedHashSet();
|
||||
|
||||
Reference in New Issue
Block a user