8246451: Reduce overhead of normalizing file paths with trailing slash

Reviewed-by: lancea
This commit is contained in:
Claes Redestad 2020-06-03 22:29:34 +02:00
parent d9fc44540e
commit 827c8865d8
2 changed files with 3 additions and 2 deletions

View File

@ -71,8 +71,9 @@ class UnixFileSystem extends FileSystem {
*/
private String normalize(String pathname, int off) {
int n = pathname.length();
while ((n > 0) && (pathname.charAt(n - 1) == '/')) n--;
while ((n > off) && (pathname.charAt(n - 1) == '/')) n--;
if (n == 0) return "/";
if (n == off) return pathname.substring(0, off);
StringBuilder sb = new StringBuilder(n);
if (off > 0) sb.append(pathname, 0, off);

View File

@ -41,7 +41,7 @@ public class FileOpen {
public String normalFile = "/test/dir/file/name.txt";
public String root = "/";
public String trailingSlash = "/test/dir/file//name.txt";
public String trailingSlash = "/test/dir/file/name.txt/";
public String notNormalizedFile = "/test/dir/file//name.txt";
@Benchmark