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 2021/06/26 05:06:23 UTC

[james-project] 05/06: [PERFORMANCE] ResultUtils::haveValidContent is doing needless work

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 f120aa65d26bf60a829782360301650b72976a6a
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Jun 21 16:17:40 2021 +0700

    [PERFORMANCE] ResultUtils::haveValidContent is doing needless work
    
     - collect is not needed
     - the enumset can be shared
    
    This takes 0.2% of CPU and 0.5% of memory allocation
---
 .../org/apache/james/mailbox/store/ResultUtils.java   | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
index 1c00394..2066469 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
@@ -44,10 +44,14 @@ import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.util.ByteSequence;
 import org.apache.james.mime4j.util.ContentUtil;
 
-import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 
 public class ResultUtils {
+    private static final EnumSet<FetchGroup.Profile> SUPPORTED_GROUPS = EnumSet.of(
+        FetchGroup.Profile.HEADERS,
+        FetchGroup.Profile.BODY_CONTENT,
+        FetchGroup.Profile.FULL_CONTENT,
+        FetchGroup.Profile.MIME_DESCRIPTOR);
 
     public static List<Header> createHeaders(MailboxMessage document) throws IOException {
         List<Header> results = new ArrayList<>();
@@ -113,18 +117,9 @@ public class ResultUtils {
 
     @VisibleForTesting
     static boolean haveValidContent(FetchGroup fetchGroup) {
-        EnumSet<FetchGroup.Profile> supportedGroups = EnumSet.of(
-            FetchGroup.Profile.HEADERS,
-            FetchGroup.Profile.BODY_CONTENT,
-            FetchGroup.Profile.FULL_CONTENT,
-            FetchGroup.Profile.MIME_DESCRIPTOR);
-
-        Collection<FetchGroup.Profile> unsupportedProfiles = fetchGroup.profiles()
+        return fetchGroup.profiles()
             .stream()
-            .filter(value -> !supportedGroups.contains(value))
-            .collect(Guavate.toImmutableSet());
-
-        return unsupportedProfiles.isEmpty();
+            .allMatch(SUPPORTED_GROUPS::contains);
     }
 
     private static void addPartContent(FetchGroup fetchGroup, MailboxMessage message, MessageResultImpl messageResult)

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