You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/06/21 03:49:35 UTC

[james-project] branch master updated: [PERFORMANCE] ImapDateTimeFormatter can be static

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 86d7048  [PERFORMANCE] ImapDateTimeFormatter can be static
86d7048 is described below

commit 86d704851c746566857b578309a9d2b327c8800a
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Jun 17 16:47:01 2021 +0700

    [PERFORMANCE] ImapDateTimeFormatter can be static
    
    0.28% of CPU is spent initializing it...
---
 .../james/util/date/ImapDateTimeFormatter.java     | 47 +++++++++++-----------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/server/container/util/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java b/server/container/util/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java
index 0a0d633..78fd735 100644
--- a/server/container/util/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java
+++ b/server/container/util/src/main/java/org/apache/james/util/date/ImapDateTimeFormatter.java
@@ -35,31 +35,32 @@ import com.google.common.collect.ImmutableMap;
 public class ImapDateTimeFormatter {
 
     private static final int INITIAL_YEAR = 1970;
+    public static final DateTimeFormatter RFC_5322_FORMATTER = new DateTimeFormatterBuilder()
+        .parseCaseInsensitive()
+        .parseLenient()
+        .optionalStart()
+            .appendText(DAY_OF_WEEK, dayOfWeek())
+            .appendLiteral(", ")
+        .optionalEnd()
+        .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
+        .appendLiteral(' ')
+        .appendText(MONTH_OF_YEAR, monthOfYear())
+        .appendLiteral(' ')
+        .appendValueReduced(YEAR, 2, 4, INITIAL_YEAR)
+        .appendLiteral(' ')
+        .appendValue(HOUR_OF_DAY, 2)
+        .appendLiteral(':')
+        .appendValue(MINUTE_OF_HOUR, 2)
+        .optionalStart()
+            .appendLiteral(':')
+            .appendValue(SECOND_OF_MINUTE, 2)
+        .optionalEnd()
+        .appendLiteral(' ')
+        .appendOffset("+HHMM", "GMT")
+        .toFormatter();
 
     public static DateTimeFormatter rfc5322() {
-        return new DateTimeFormatterBuilder()
-                .parseCaseInsensitive()
-                .parseLenient()
-                .optionalStart()
-                    .appendText(DAY_OF_WEEK, dayOfWeek())
-                    .appendLiteral(", ")
-                .optionalEnd()
-                .appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
-                .appendLiteral(' ')
-                .appendText(MONTH_OF_YEAR, monthOfYear())
-                .appendLiteral(' ')
-                .appendValueReduced(YEAR, 2, 4, INITIAL_YEAR)
-                .appendLiteral(' ')
-                .appendValue(HOUR_OF_DAY, 2)
-                .appendLiteral(':')
-                .appendValue(MINUTE_OF_HOUR, 2)
-                .optionalStart()
-                    .appendLiteral(':')
-                    .appendValue(SECOND_OF_MINUTE, 2)
-                .optionalEnd()
-                .appendLiteral(' ')
-                .appendOffset("+HHMM", "GMT")
-                .toFormatter();
+        return RFC_5322_FORMATTER;
     }
 
     private static ImmutableMap<Long, String> monthOfYear() {

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