MAILET-124 Add shortcut optimization on Or matcher

It is important as it might avoid some expensive matcher execution


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a78c8547
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a78c8547
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a78c8547

Branch: refs/heads/master
Commit: a78c8547e7b77675a6ba007f4d8979428e1d7d7b
Parents: 5636d89
Author: Benoit Tellier <btell...@linagora.com>
Authored: Thu Sep 8 14:50:00 2016 +0200
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Thu Sep 15 12:05:20 2016 +0200

----------------------------------------------------------------------
 .../james/mailetcontainer/impl/matchers/Or.java  | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a78c8547/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
 
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
index cc7ab84..5d4f3c1 100644
--- 
a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
+++ 
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java
@@ -19,15 +19,15 @@
 
 package org.apache.james.mailetcontainer.impl.matchers;
 
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.Mail;
-import org.apache.mailet.Matcher;
-
 import java.util.Collection;
-import java.util.Iterator;
-import java.util.ArrayList;
+import java.util.HashSet;
+
 import javax.mail.MessagingException;
 
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+
 import com.google.common.collect.ImmutableSet;
 
 public class Or extends GenericCompositeMatcher {
@@ -40,14 +40,17 @@ public class Or extends GenericCompositeMatcher {
      *         child matchers.
      */
     public Collection<MailAddress> match(Mail mail) throws MessagingException {
-        ImmutableSet.Builder<MailAddress> result = ImmutableSet.builder();
+        HashSet<MailAddress> result = new HashSet<MailAddress>();
         for (Matcher matcher : getMatchers()) {
             Collection<MailAddress> matchResult = matcher.match(mail);
             if (matchResult != null) {
                 result.addAll(matchResult);
             }
+            if (result.size() == mail.getRecipients().size()) {
+                break;
+            }
         }
-        return result.build();
+        return ImmutableSet.copyOf(result);
     }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to