FileUtil: comparing only names (-1 minute on Chromium)

This commit is contained in:
Anton Makeev
2012-11-30 11:12:46 +01:00
parent b50d6d8945
commit b144bfa85d
2 changed files with 15 additions and 6 deletions
@@ -24,16 +24,16 @@ import com.intellij.openapi.util.io.FileUtil;
public abstract class SpecificNameItemProcessor implements PsiFileSystemItemProcessor {
private final String myName;
public String getName() {
return myName;
}
protected SpecificNameItemProcessor(String name) {
myName = name;
}
public String getName() {
return myName;
}
@Override
public boolean acceptItem(String name, boolean isDirectory) {
return FileUtil.pathsEqual(myName, name);
return FileUtil.namesEqual(myName, name);
}
}
@@ -798,10 +798,19 @@ public class FileUtil extends FileUtilRt {
path1 = toCanonicalPath(path1);
path2 = toCanonicalPath(path2);
//noinspection ConstantConditions
return PATH_HASHING_STRATEGY.equals(path1, path2);
}
/**
* optimized version of pathsEqual - it only compares pure names, without file separators
*/
public static boolean namesEqual(@Nullable String name1, @Nullable String name2) {
if (name1 == name2) return true;
if (name1 == null || name2 == null) return false;
return PATH_HASHING_STRATEGY.equals(name1, name2);
}
public static int compareFiles(@Nullable File file1, @Nullable File file2) {
return comparePaths(file1 == null ? null : file1.getPath(), file2 == null ? null : file2.getPath());
}