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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e2faf88ecbf0bc0ee64b03ea8e7cbd90051e7b97
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Apr 7 13:41:47 2021 +0200

    CAMEL-16462: camel-core - Optimize RecipientList EIP to reduce object 
allocations.
---
 .../src/main/java/org/apache/camel/processor/MulticastProcessor.java  | 4 ++--
 .../main/java/org/apache/camel/processor/RecipientListProcessor.java  | 4 ++--
 .../src/main/java/org/apache/camel/processor/Splitter.java            | 2 +-
 core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java | 3 +++
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index 96d3502..a7e913b 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -326,7 +326,7 @@ public class MulticastProcessor extends 
AsyncProcessorSupport
     protected boolean process(Exchange exchange, AsyncCallback callback, 
Iterator iter, int size) {
         Iterable<ProcessorExchangePair> pairs;
         try {
-            pairs = createProcessorExchangePairs(exchange, iter);
+            pairs = createProcessorExchangePairs(exchange, iter, size);
         } catch (Throwable e) {
             exchange.setException(e);
             // unexpected exception was thrown, maybe from iterator etc. so do 
not regard as exhausted
@@ -925,7 +925,7 @@ public class MulticastProcessor extends 
AsyncProcessorSupport
         return exchange.getProperty(ExchangePropertyKey.MULTICAST_INDEX, 
Integer.class);
     }
 
-    protected Iterable<ProcessorExchangePair> 
createProcessorExchangePairs(Exchange exchange, Iterator<?> iter)
+    protected Iterable<ProcessorExchangePair> 
createProcessorExchangePairs(Exchange exchange, Iterator<?> iter, int size)
             throws Exception {
         List<ProcessorExchangePair> result = new 
ArrayList<>(processors.size());
 
diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
index c5927fc..2e7021d 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java
@@ -188,10 +188,10 @@ public class RecipientListProcessor extends 
MulticastProcessor {
     }
 
     @Override
-    protected Iterable<ProcessorExchangePair> 
createProcessorExchangePairs(Exchange exchange, Iterator<?> iter)
+    protected Iterable<ProcessorExchangePair> 
createProcessorExchangePairs(Exchange exchange, Iterator<?> iter, int size)
             throws Exception {
         // here we iterate the recipient lists and create the exchange pair 
for each of those
-        List<ProcessorExchangePair> result = new ArrayList<>();
+        List<ProcessorExchangePair> result = size > 0 ? new ArrayList<>(size) 
: new ArrayList<>();
 
         // at first we must lookup the endpoint and acquire the producer which 
can send to the endpoint
         int index = 0;
diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Splitter.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Splitter.java
index 217b5bf..dd69a2f 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Splitter.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Splitter.java
@@ -159,7 +159,7 @@ public class Splitter extends MulticastProcessor implements 
AsyncProcessor, Trac
     }
 
     @Override
-    protected Iterable<ProcessorExchangePair> 
createProcessorExchangePairs(Exchange exchange, Iterator<?> iter)
+    protected Iterable<ProcessorExchangePair> 
createProcessorExchangePairs(Exchange exchange, Iterator<?> iter, int size)
             throws Exception {
         // iter is only currently used by Recipient List EIP so its null
 
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java 
b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
index 724a9cb..3a0be31 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -891,6 +891,9 @@ public final class ObjectHelper {
         return false;
     }
 
+    /**
+     * Used by camel-bean
+     */
     public static int arrayLength(Object[] pojo) {
         return pojo.length;
     }

Reply via email to