8274276: Cache normalizedBase URL in URLClassPath.FileLoader

Reviewed-by: dfuchs
This commit is contained in:
Sergey Tsypanov 2021-09-28 17:18:55 +00:00 committed by Daniel Fuchs
parent b36881fa3b
commit 94f5e807c9

View file

@ -597,7 +597,7 @@ public class URLClassPath {
/* /*
* Returns the base URL for this Loader. * Returns the base URL for this Loader.
*/ */
URL getBaseURL() { final URL getBaseURL() {
return base; return base;
} }
@ -1199,7 +1199,8 @@ public class URLClassPath {
*/ */
private static class FileLoader extends Loader { private static class FileLoader extends Loader {
/* Canonicalized File */ /* Canonicalized File */
private File dir; private final File dir;
private final URL normalizedBase;
/* /*
* Creates a new FileLoader for the specified URL with a file protocol. * Creates a new FileLoader for the specified URL with a file protocol.
@ -1209,6 +1210,7 @@ public class URLClassPath {
String path = url.getFile().replace('/', File.separatorChar); String path = url.getFile().replace('/', File.separatorChar);
path = ParseUtil.decode(path); path = ParseUtil.decode(path);
dir = (new File(path)).getCanonicalFile(); dir = (new File(path)).getCanonicalFile();
normalizedBase = new URL(getBaseURL(), ".");
} }
/* /*
@ -1227,7 +1229,6 @@ public class URLClassPath {
Resource getResource(final String name, boolean check) { Resource getResource(final String name, boolean check) {
final URL url; final URL url;
try { try {
URL normalizedBase = new URL(getBaseURL(), ".");
url = new URL(getBaseURL(), ParseUtil.encodePath(name, false)); url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));
if (url.getFile().startsWith(normalizedBase.getFile()) == false) { if (url.getFile().startsWith(normalizedBase.getFile()) == false) {