< prev index next >

src/java.base/share/classes/java/net/URI.java

Print this page
rev 15833 : 8168073: Speed up URI creation during module bootstrap
Reviewed-by: alanb

@@ -35,10 +35,13 @@
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
 import java.nio.charset.CharacterCodingException;
 import java.text.Normalizer;
+import jdk.internal.loader.URLClassPath;
+import jdk.internal.misc.JavaNetAccess;
+import jdk.internal.misc.SharedSecrets;
 import sun.nio.cs.ThreadLocalCoders;
 
 import java.lang.Character;             // for javadoc
 import java.lang.NullPointerException;  // for javadoc
 

@@ -818,10 +821,19 @@
                             null, null, fragment))
             .parse(false);
     }
 
     /**
+     * Constructs a simple URI consisting of only a scheme and a pre-validated
+     * path. Provides a fast-path for some internal cases.
+     */
+    URI(String scheme, String path) {
+        this.scheme = scheme;
+        this.path = path;
+    }
+
+    /**
      * Creates a URI by parsing the given string.
      *
      * <p> This convenience factory method works as if by invoking the {@link
      * #URI(String)} constructor; any {@link URISyntaxException} thrown by the
      * constructor is caught and wrapped in a new {@link

@@ -3569,7 +3581,15 @@
 
             return p;
         }
 
     }
-
+    static {
+        SharedSecrets.setJavaNetAccess(
+            new JavaNetAccess() {
+                public URI createURI(String scheme, String path) {
+                    return new URI(scheme, path);
+                }
+            }
+        );
+    }
 }
< prev index next >