changeset 48245:a9160acae595

8192892: Improve JrtPath::getResolved fast-path test 8175891: JrtPath::resolve off-by-one pre-sizing cause for memory pressure Reviewed-by: sundar, jlaskey
author redestad
date Fri, 01 Dec 2017 17:00:34 +0100
parents 3d4bd4d33a67
children 26f1193f1348
files src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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();