Skip to content

Commit

Permalink
Optimize StringUtils.cleanPath
Browse files Browse the repository at this point in the history
Add an early exit to `StringUtils.cleanPath` to save array creating and
string concatenation. With a typical Spring application, the `cleanPath`
method can be called over 600 times, often with a path constructed by
a `ClassPathResource` that is likely to already be clean.

Closes gh-22568
  • Loading branch information
philwebb authored and jhoeller committed Mar 22, 2019
1 parent 19fb697 commit a57d6ba
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@ public static String cleanPath(String path) {
}
String pathToUse = replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR);

// Shortcut if there is no work to do
if (pathToUse.indexOf('.') == -1) {
return pathToUse;
}

// Strip prefix from path to analyze, to not treat it as part of the
// first path element. This is necessary to correctly parse paths like
// "file:core/../core/io/Resource.class", where the ".." should just
Expand Down

0 comments on commit a57d6ba

Please sign in to comment.