You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/09 02:25:03 UTC

[james-project] 05/07: [PERF] Decode UTF-7 only if needed

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 707d520780eb8c7db25ff1c12b158b378e42f0fc
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri May 6 11:10:19 2022 +0700

    [PERF] Decode UTF-7 only if needed
    
    UTF-7 decoding is only needed if some characters
    are UTF-7 encoded, which happens if the switching
    character `&` is present.
    
    If absent we can skip the UTF-7 decoding step,
    which saves ~10% of IMAP command parsing allocation
    (string copy and coder charBuffer allocation) and
    ~6% of IMAP command parsing CPU time.
---
 .../main/java/org/apache/james/imap/api/display/ModifiedUtf7.java    | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java b/protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java
index f132e87189..e39ffd91e2 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/display/ModifiedUtf7.java
@@ -22,11 +22,13 @@ import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 
 import com.beetstra.jutf7.CharsetProvider;
+import com.google.common.base.CharMatcher;
 
 /**
  * This class has some methods included which helps to encode/decode modified UTF7
  */
 public class ModifiedUtf7 {
+    private static final CharMatcher UNENCODED_CHAR_MATCHER = CharMatcher.isNot('&');
 
     private static final Charset X_MODIFIED_UTF_7_CHARSET = new CharsetProvider().charsetForName("X-MODIFIED-UTF-7");
 
@@ -37,6 +39,9 @@ public class ModifiedUtf7 {
      * @return decoded value
      */
     public static String decodeModifiedUTF7(String input) {
+        if (UNENCODED_CHAR_MATCHER.matchesAllOf(input)) {
+            return input;
+        }
         return X_MODIFIED_UTF_7_CHARSET.decode(ByteBuffer.wrap(input.getBytes())).toString();
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org