< 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, mchung, psandoz

*** 35,44 **** --- 35,47 ---- 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.JavaNetUriAccess; + import jdk.internal.misc.SharedSecrets; import sun.nio.cs.ThreadLocalCoders; import java.lang.Character; // for javadoc import java.lang.NullPointerException; // for javadoc
*** 818,827 **** --- 821,849 ---- 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) { + assert validSchemeAndPath(scheme, path); + this.scheme = scheme; + this.path = path; + } + + private static boolean validSchemeAndPath(String scheme, String path) { + try { + URI u = new URI(scheme + ":" + path); + return scheme.equals(u.scheme) && path.equals(u.path); + } catch (URISyntaxException e) { + return false; + } + } + + /** * 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,3575 **** return p; } } ! } --- 3591,3605 ---- return p; } } ! static { ! SharedSecrets.setJavaNetUriAccess( ! new JavaNetUriAccess() { ! public URI create(String scheme, String path) { ! return new URI(scheme, path); ! } ! } ! ); ! } }
< prev index next >