Repository: camel
Updated Branches:
  refs/heads/master f824fb0bf -> a6d702959


Optimise bean to not create unnessary objects. Optimise internal processor to 
use Object[] instead of ArrayList for states.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/39ef98ee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/39ef98ee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/39ef98ee

Branch: refs/heads/master
Commit: 39ef98eefeb165416a3cd8c76845012909a185dc
Parents: 7e85684
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Jun 1 22:27:45 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Jun 2 09:05:13 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   | 21 +++++++++++++-------
 .../camel/processor/CamelInternalProcessor.java | 11 +++++-----
 .../processor/SharedCamelInternalProcessor.java | 11 +++++-----
 .../camel/component/bean/BeanInfoTest.java      | 12 ++++++++---
 4 files changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/39ef98ee/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java 
b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index 21251f1..2e99efa 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -1226,7 +1226,7 @@ public class BeanInfo {
     }
 
     /**
-     * Gets the list of methods sorted by A..Z method name.
+     * Gets the list of methods (unsorted)
      *
      * @return the methods.
      */
@@ -1239,13 +1239,20 @@ public class BeanInfo {
         for (Collection<MethodInfo> col : operations.values()) {
             methods.addAll(col);
         }
+        return methods;
+    }
 
-        // sort the methods by name A..Z
-        methods.sort(new Comparator<MethodInfo>() {
-            public int compare(MethodInfo o1, MethodInfo o2) {
-                return 
o1.getMethod().getName().compareTo(o2.getMethod().getName());
-            }
-        });
+    /**
+     * Gets the list of methods sorted by A..Z method name.
+     *
+     * @return the methods.
+     */
+    public List<MethodInfo> getSortedMethods() {
+        List<MethodInfo> methods = getMethods();
+        if (methods.size() > 1) {
+            // sort the methods by name A..Z
+            methods.sort(Comparator.comparing(o -> o.getMethod().getName()));
+        }
         return methods;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/39ef98ee/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index 2514d37..d315ecc 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -140,13 +140,14 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
             return true;
         }
 
-        final List<Object> states = new ArrayList<Object>(advices.size());
+        // optimise to use object array for states
+        final Object[] states = new Object[advices.size()];
         // optimise for loop using index access to avoid creating iterator 
object
         for (int i = 0; i < advices.size(); i++) {
             CamelInternalProcessorAdvice task = advices.get(i);
             try {
                 Object state = task.before(exchange);
-                states.add(state);
+                states[i] = state;
             } catch (Throwable e) {
                 exchange.setException(e);
                 callback.done(true);
@@ -225,11 +226,11 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
      */
     private final class InternalCallback implements AsyncCallback {
 
-        private final List<Object> states;
+        private final Object[] states;
         private final Exchange exchange;
         private final AsyncCallback callback;
 
-        private InternalCallback(List<Object> states, Exchange exchange, 
AsyncCallback callback) {
+        private InternalCallback(Object[] states, Exchange exchange, 
AsyncCallback callback) {
             this.states = states;
             this.exchange = exchange;
             this.callback = callback;
@@ -245,7 +246,7 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
             try {
                 for (int i = advices.size() - 1; i >= 0; i--) {
                     CamelInternalProcessorAdvice task = advices.get(i);
-                    Object state = states.get(i);
+                    Object state = states[i];
                     try {
                         task.after(exchange, state);
                     } catch (Throwable e) {

http://git-wip-us.apache.org/repos/asf/camel/blob/39ef98ee/camel-core/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
 
b/camel-core/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
index af69b2b..9bf76d2 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
@@ -125,13 +125,14 @@ public class SharedCamelInternalProcessor {
             return true;
         }
 
-        final List<Object> states = new ArrayList<Object>(advices.size());
+        // optimise to use object array for states
+        final Object[] states = new Object[advices.size()];
         // optimise for loop using index access to avoid creating iterator 
object
         for (int i = 0; i < advices.size(); i++) {
             CamelInternalProcessorAdvice task = advices.get(i);
             try {
                 Object state = task.before(exchange);
-                states.add(state);
+                states[i] = state;
             } catch (Throwable e) {
                 exchange.setException(e);
                 callback.done(true);
@@ -205,12 +206,12 @@ public class SharedCamelInternalProcessor {
      */
     private final class InternalCallback implements AsyncCallback {
 
-        private final List<Object> states;
+        private final Object[] states;
         private final Exchange exchange;
         private final AsyncCallback callback;
         private final Processor resultProcessor;
 
-        private InternalCallback(List<Object> states, Exchange exchange, 
AsyncCallback callback, Processor resultProcessor) {
+        private InternalCallback(Object[] states, Exchange exchange, 
AsyncCallback callback, Processor resultProcessor) {
             this.states = states;
             this.exchange = exchange;
             this.callback = callback;
@@ -235,7 +236,7 @@ public class SharedCamelInternalProcessor {
             try {
                 for (int i = advices.size() - 1; i >= 0; i--) {
                     CamelInternalProcessorAdvice task = advices.get(i);
-                    Object state = states.get(i);
+                    Object state = states[i];
                     try {
                         task.after(exchange, state);
                     } catch (Throwable e) {

http://git-wip-us.apache.org/repos/asf/camel/blob/39ef98ee/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java 
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java
index 31c919f..b541345 100644
--- a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java
@@ -50,9 +50,15 @@ public class BeanInfoTest extends TestCase {
 
         List<MethodInfo> operations = info.getMethods();
         assertEquals(3, operations.size());
-        assertEquals("inOnlyMethod", operations.get(0).getMethod().getName());
-        assertEquals("inOutMethod", operations.get(1).getMethod().getName());
-        assertEquals("robustInOnlyMethod", 
operations.get(2).getMethod().getName());
+
+        long size = operations.stream().filter(m -> 
m.getMethod().getName().equals("inOnlyMethod")).count();
+        assertEquals(1, size);
+
+        size = operations.stream().filter(m -> 
m.getMethod().getName().equals("inOutMethod")).count();
+        assertEquals(1, size);
+
+        size = operations.stream().filter(m -> 
m.getMethod().getName().equals("robustInOnlyMethod")).count();
+        assertEquals(1, size);
     }
 
     public void testMethodPatternUsingMethodAnnotations() throws Exception {

Reply via email to