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 140226afd Improve performance of encoding Uris (#660)
140226afd is described below

commit 140226afdf42f1d538c12896e1ea01b1a0858897
Author: Anthony Goubard <anthony.goub...@japplis.com>
AuthorDate: Mon Mar 24 14:39:59 2025 +0100

    Improve performance of encoding Uris (#660)
    
    * Improved performance of UriParser.normalisePath
    
    * Improved performance of UriParser.extractScheme
    
    * Improved performance of UriParser.encode
    
    * Improved performance of UriParser.encode
    Make tests compile and uncommented optimisation
    
    * Fix CRLF to LF
---
 .../src/main/java/org/apache/commons/vfs2/provider/UriParser.java  | 3 +++
 .../java/org/apache/commons/vfs2/provider/UriParserBenchmark.java  | 7 +++++++
 2 files changed, 10 insertions(+)

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 757c0990d..273c9c083 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
@@ -217,6 +217,9 @@ public final class UriParser {
         }
         final StringBuilder buffer = new StringBuilder(decodedStr);
         encode(buffer, 0, buffer.length(), reserved);
+        if (buffer.length() == decodedStr.length()) { // No encoding happened
+            return decodedStr;
+        }
         return buffer.toString();
     }
 
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 712ef209a..5d9db482f 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,8 @@ 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 PATH_TO_ENCODE = 
"file:///this/is/path/to/encode/for/testing/encode.perf";
+    private static final char[] ENCODE_RESERVED = new char[] {' ', '#'};
 
     @Benchmark
     public void normalisePath() throws FileSystemException {
@@ -36,4 +38,9 @@ public class UriParserBenchmark {
         UriParser.fixSeparators(path);
         UriParser.normalisePath(path);
     }
+
+    @Benchmark
+    public void encode() throws FileSystemException {
+        UriParser.encode(PATH_TO_ENCODE, ENCODE_RESERVED);
+    }
 }

Reply via email to