Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance of UriParser#extractScheme #614

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public static String extractScheme(final String[] schemes, final String uri, fin
buffer.append(uri);
}
for (final String scheme : schemes) {
if (uri.startsWith(scheme + ":")) {
if (uri.startsWith(scheme) && uri.length() > scheme.length() && uri.charAt(scheme.length()) == ':') {
if (buffer != null) {
buffer.delete(0, uri.indexOf(':') + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@
public class UriParserBenchmark {

private static final String PATH_TO_NORMALIZE = "file:///this/../is/a%2flong%2Fpath/./for testing/normlisePath%2fmethod.txt";
private static final String[] SCHEMES = {"file", "ftp", "ftps", "webdav", "temp", "ram", "http", "https", "sftp", "zip", "jar", "tgz", "gz"};

@Benchmark
public void normalisePath() throws FileSystemException {
final StringBuilder path = new StringBuilder(PATH_TO_NORMALIZE);
UriParser.fixSeparators(path);
UriParser.normalisePath(path);
}

@Benchmark
public void extractScheme() throws FileSystemException {
UriParser.extractScheme(SCHEMES, PATH_TO_NORMALIZE);
}
}