From 49afa69d541d8bcc1abbadd039b8699399c110a8 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 13 Jan 2012 22:10:21 +0400 Subject: [PATCH] when processing all resources with names, use available cache to avoid scanning all class sources --- .../src/com/intellij/util/lang/ClassPath.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/util/lang/ClassPath.java b/platform/util/src/com/intellij/util/lang/ClassPath.java index 92151d9c071e..25bd86519f44 100644 --- a/platform/util/src/com/intellij/util/lang/ClassPath.java +++ b/platform/util/src/com/intellij/util/lang/ClassPath.java @@ -20,9 +20,11 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.SmartList; import com.intellij.util.containers.HashMap; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import sun.misc.Resource; @@ -103,6 +105,7 @@ class ClassPath { push(urls); } + // Accessed by reflection from PluginClassLoader void addURL(URL url) { push(new URL[]{url}); } @@ -114,8 +117,7 @@ class ClassPath { try { int i; if (myCanUseCache) { - final List loaders = myCache.getLoaders(s); - for (Loader loader : loaders) { + for (Loader loader : getLoaders(s)) { final Resource resource = loader.getResource(s, flag); if (resource != null) { if (ourDumpOrder) { @@ -152,6 +154,10 @@ class ClassPath { } } + private @NotNull List getLoaders(String s) { + return myCache.getLoaders(s); + } + public Enumeration getResources(final String name, final boolean check) { return new MyEnumeration(name, check); } @@ -233,21 +239,46 @@ class ClassPath { private Resource myRes = null; private final String myName; private final boolean myCheck; + private final List myLoaders; public MyEnumeration(String name, boolean check) { myName = name; myCheck = check; + List loaders = null; + + if (myCanUseCache) { + synchronized (myUrls) { + if (myUrls.isEmpty()) { + loaders = getLoaders(name); + if (!name.endsWith("/")) { + loaders = new SmartList(loaders); + loaders.addAll(getLoaders(name + "/")); + } + } + } + } + + myLoaders = loaders; } private boolean next() { if (myRes != null) return true; Loader loader; - while ((loader = getLoader(myIndex++)) != null) { - myRes = loader.getResource(myName, myCheck); - if (myRes != null) return true; + + if (myLoaders != null) { + while (myIndex < myLoaders.size()) { + myRes = myLoaders.get(myIndex++).getResource(myName, myCheck); + if (myRes != null) return true; + } + } else { + while ((loader = getLoader(myIndex++)) != null) { + myRes = loader.getResource(myName, myCheck); + if (myRes != null) return true; + } } + return false; }