This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push: new f92f2165f Improved performance of UriParser#extractScheme (#614) f92f2165f is described below commit f92f2165f0d6a6005bbffbff0fb1901843387d14 Author: Anthony Goubard <anthony.goub...@japplis.com> AuthorDate: Thu May 1 20:15:08 2025 +0200 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 3d22ccf69c47a9e9e4f0d97f0fb7c3e9b1f4da92. * Improved performance of UriParser#extractScheme * Improved performance of UriParser#extractScheme --- .../src/main/java/org/apache/commons/vfs2/provider/UriParser.java | 2 +- .../java/org/apache/commons/vfs2/provider/UriParserBenchmark.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java index 273c9c083..2aeced7fd 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java @@ -434,7 +434,7 @@ public final class UriParser { 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); } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserBenchmark.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserBenchmark.java index 5d9db482f..c9ec4deff 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserBenchmark.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/UriParserBenchmark.java @@ -29,6 +29,7 @@ import org.openjdk.jmh.annotations.Warmup; 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"}; private static final String PATH_TO_ENCODE = "file:///this/is/path/to/encode/for/testing/encode.perf"; private static final char[] ENCODE_RESERVED = new char[] {' ', '#'}; @@ -40,6 +41,10 @@ public class UriParserBenchmark { } @Benchmark + public void extractScheme() throws FileSystemException { + UriParser.extractScheme(SCHEMES, PATH_TO_NORMALIZE); + } + public void encode() throws FileSystemException { UriParser.encode(PATH_TO_ENCODE, ENCODE_RESERVED); }