8192892: Improve JrtPath::getResolved fast-path test
authorredestad
Fri, 01 Dec 2017 17:00:34 +0100
changeset 48039 a9160acae595
parent 48038 3d4bd4d33a67
child 48040 26f1193f1348
8192892: Improve JrtPath::getResolved fast-path test 8175891: JrtPath::resolve off-by-one pre-sizing cause for memory pressure Reviewed-by: sundar, jlaskey
src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java
--- a/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java	Fri Dec 01 05:27:44 2017 +0000
+++ b/src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java	Fri Dec 01 17:00:34 2017 +0100
@@ -274,7 +274,7 @@
         if (o.path.length() == 0) {
             return this;
         }
-        StringBuilder sb = new StringBuilder(path.length() + o.path.length());
+        StringBuilder sb = new StringBuilder(path.length() + o.path.length() + 1);
         sb.append(path);
         if (path.charAt(path.length() - 1) != '/')
             sb.append('/');
@@ -478,12 +478,15 @@
 
     // Remove DotSlash(./) and resolve DotDot (..) components
     private String getResolved() {
-        if (path.length() == 0) {
+        int length = path.length();
+        if (length == 0 || (path.indexOf("./") == -1 && path.charAt(length - 1) != '.')) {
             return path;
+        } else {
+            return resolvePath();
         }
-        if (path.indexOf('.') == -1) {
-            return path;
-        }
+    }
+
+    private String resolvePath() {
         int length = path.length();
         char[] to = new char[length];
         int nc = getNameCount();