Skip to content
Permalink
Browse files
8246451: Reduce overhead of normalizing file paths with trailing slash
Reviewed-by: lancea
  • Loading branch information
cl4es committed Jun 3, 2020
1 parent d9fc445 commit 827c8865d8aab72cca3951fc1f5fbb3e23ba1c14
Showing 2 changed files with 3 additions and 2 deletions.
@@ -71,8 +71,9 @@ public char getPathSeparator() {
*/
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);
@@ -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

0 comments on commit 827c886

Please sign in to comment.