Skip to content

Commit f92f216

Browse files
authored
Improved performance of UriParser#extractScheme (#614)
* Improved performance of UriParser.normalisePath * Improved performance of UriParser.extractScheme * Aligned measurement with master branch * Keep the same line feed * Revert "Keep the same line feed" This reverts commit 3d22ccf. * Improved performance of UriParser#extractScheme * Improved performance of UriParser#extractScheme
1 parent 18b0bce commit f92f216

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public static String extractScheme(final String[] schemes, final String uri, fin
434434
buffer.append(uri);
435435
}
436436
for (final String scheme : schemes) {
437-
if (uri.startsWith(scheme + ":")) {
437+
if (uri.startsWith(scheme) && uri.length() > scheme.length() && uri.charAt(scheme.length()) == ':') {
438438
if (buffer != null) {
439439
buffer.delete(0, uri.indexOf(':') + 1);
440440
}

commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserBenchmark.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
public class UriParserBenchmark {
3030

3131
private static final String PATH_TO_NORMALIZE = "file:///this/../is/a%2flong%2Fpath/./for testing/normlisePath%2fmethod.txt";
32+
private static final String[] SCHEMES = {"file", "ftp", "ftps", "webdav", "temp", "ram", "http", "https", "sftp", "zip", "jar", "tgz", "gz"};
3233
private static final String PATH_TO_ENCODE = "file:///this/is/path/to/encode/for/testing/encode.perf";
3334
private static final char[] ENCODE_RESERVED = new char[] {' ', '#'};
3435

@@ -40,6 +41,10 @@ public void normalisePath() throws FileSystemException {
4041
}
4142

4243
@Benchmark
44+
public void extractScheme() throws FileSystemException {
45+
UriParser.extractScheme(SCHEMES, PATH_TO_NORMALIZE);
46+
}
47+
4348
public void encode() throws FileSystemException {
4449
UriParser.encode(PATH_TO_ENCODE, ENCODE_RESERVED);
4550
}

0 commit comments

Comments
 (0)