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-mime4j.git

commit d10cd40fa46785f4efcc45b79c15d40d4fcfcd33
Author: Benoit TELLIER <[email protected]>
AuthorDate: Sun Mar 8 22:07:53 2026 +0100

    [PERF] Boundary matching — QS table rebuilt every call
    
      The Quick Search shift-table is rebuilt on every indexOf() call,
      but the MIME boundary is fixed for the entire lifetime of a
      MimeBoundaryInputStream.
    
      Pre-compute and cache the shift-table inside
      MimeBoundaryInputStream at construction time. Direct gain
      on all multipart messages.
---
 .../james/mime4j/io/BufferedLineReaderInputStream.java   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git 
a/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
 
b/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
index 4dea0b44..ddb29d2b 100644
--- 
a/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
+++ 
b/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
@@ -58,6 +58,7 @@ public class BufferedLineReaderInputStream extends 
LineReaderInputStream {
     private int bufpos;
     private int buflen;
     private int[] shiftTable;
+    private byte[] cachedShiftPattern;
 
     private final int maxLineLen;
 
@@ -270,12 +271,15 @@ public class BufferedLineReaderInputStream extends 
LineReaderInputStream {
         }
 
 
-        for (int i = 0; i < shiftTable.length; i++) {
-            shiftTable[i] = pattern.length + 1;
-        }
-        for (int i = 0; i < pattern.length; i++) {
-            int x = pattern[i] & 0xff;
-            shiftTable[x] = pattern.length - i;
+        if (pattern != cachedShiftPattern) {
+            for (int i = 0; i < shiftTable.length; i++) {
+                shiftTable[i] = pattern.length + 1;
+            }
+            for (int i = 0; i < pattern.length; i++) {
+                int x = pattern[i] & 0xff;
+                shiftTable[x] = pattern.length - i;
+            }
+            cachedShiftPattern = pattern;
         }
 
         int j = 0;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to