8246451: Reduce overhead of normalizing file paths with trailing slash
Reviewed-by: lancea
This commit is contained in:
parent
d9fc44540e
commit
827c8865d8
@ -71,8 +71,9 @@ class UnixFileSystem extends FileSystem {
|
|||||||
*/
|
*/
|
||||||
private String normalize(String pathname, int off) {
|
private String normalize(String pathname, int off) {
|
||||||
int n = pathname.length();
|
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 == 0) return "/";
|
||||||
|
if (n == off) return pathname.substring(0, off);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(n);
|
StringBuilder sb = new StringBuilder(n);
|
||||||
if (off > 0) sb.append(pathname, 0, off);
|
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 normalFile = "/test/dir/file/name.txt";
|
||||||
public String root = "/";
|
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";
|
public String notNormalizedFile = "/test/dir/file//name.txt";
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
|
Loading…
x
Reference in New Issue
Block a user