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/03/16 01:18:32 UTC
[james-project] 02/11: [PERF] IMAP SELECT decoding should not rely on exception
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 16afc8a0e308e458755dcd1061bb0b93302e56e7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 10 16:01:37 2022 +0700
[PERF] IMAP SELECT decoding should not rely on exception
Filling the stacktrace for this represents 30% of decoding
time of a workload of repeat(SELECT, FETCH)...
---
.../apache/james/imap/decode/ImapRequestLineReader.java | 15 +++++++++++++++
.../decode/parser/AbstractSelectionCommandParser.java | 10 +++-------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
index 25a32cc..045ebec 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
@@ -34,6 +34,7 @@ import java.nio.charset.CodingErrorAction;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import javax.mail.Flags;
@@ -93,6 +94,20 @@ public abstract class ImapRequestLineReader {
return next;
}
+ public Optional<Character> nextWordCharLenient() throws DecodingException {
+ char next = nextChar();
+ while (next == ' ') {
+ consume();
+ next = nextChar();
+ }
+
+ if (next == '\r' || next == '\n') {
+ return Optional.empty();
+ }
+
+ return Optional.of(next);
+ }
+
/**
* Reads the next character in the current line. This method will continue
* to return the same character until the {@link #consume()} method is
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
index 5014107..8959299 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
@@ -52,13 +52,9 @@ public abstract class AbstractSelectionCommandParser extends AbstractImapCommand
UidRange[] uidSet = null;
UidRange[] knownUidSet = null;
IdRange[] knownSequenceSet = null;
-
- char c = Character.UNASSIGNED;
- try {
- c = request.nextWordChar();
- } catch (DecodingException e) {
- // This is expected if the request has no options like CONDSTORE and QRESYNC
- }
+
+ char c = request.nextWordCharLenient()
+ .orElse((char) Character.UNASSIGNED);
// Ok an option was found
if (c == '(') {
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org