CAMEL-11358: Optimise for loops that are in hot spots to be index based to 
yield less memory usage becase no temporary iterator object instance is created 
for the looping.


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

Branch: refs/heads/master
Commit: 6651c1b0b1fb7614a0058bc55868c9c5502c490f
Parents: 13f5b04
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon May 29 15:18:59 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon May 29 15:18:59 2017 +0200

----------------------------------------------------------------------
 .../camel/processor/CamelInternalProcessor.java |  7 +++--
 .../processor/SharedCamelInternalProcessor.java |  5 ++-
 .../java/org/apache/camel/util/EventHelper.java | 32 +++++++++++++++-----
 3 files changed, 33 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6651c1b0/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 5599181..82d26c1 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
@@ -141,7 +141,9 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
 
         final List<Object> states = new ArrayList<Object>(advices.size());
-        for (CamelInternalProcessorAdvice task : advices) {
+        // 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);
@@ -234,6 +236,7 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
 
         @Override
+        @SuppressWarnings("unchecked")
         public void done(boolean doneSync) {
             // NOTE: if you are debugging Camel routes, then all the code in 
the for loop below is internal only
             // so you can step straight to the finally block and invoke the 
callback
@@ -245,7 +248,7 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
                     Object state = states.get(i);
                     try {
                         task.after(exchange, state);
-                    } catch (Exception e) {
+                    } catch (Throwable e) {
                         exchange.setException(e);
                         // allow all advices to complete even if there was an 
exception
                     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6651c1b0/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 3dc4086..af69b2b 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
@@ -126,7 +126,9 @@ public class SharedCamelInternalProcessor {
         }
 
         final List<Object> states = new ArrayList<Object>(advices.size());
-        for (CamelInternalProcessorAdvice task : advices) {
+        // 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);
@@ -216,6 +218,7 @@ public class SharedCamelInternalProcessor {
         }
 
         @Override
+        @SuppressWarnings("unchecked")
         public void done(boolean doneSync) {
             // NOTE: if you are debugging Camel routes, then all the code in 
the for loop below is internal only
             // so you can step straight to the finally block and invoke the 
callback

http://git-wip-us.apache.org/repos/asf/camel/blob/6651c1b0/camel-core/src/main/java/org/apache/camel/util/EventHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EventHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/EventHelper.java
index 66c14eb..bf751ef 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EventHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EventHelper.java
@@ -534,7 +534,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -578,7 +580,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -622,7 +626,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -667,7 +673,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -712,7 +720,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -756,7 +766,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -800,7 +812,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }
@@ -844,7 +858,9 @@ public final class EventHelper {
 
         boolean answer = false;
         EventObject event = null;
-        for (EventNotifier notifier : notifiers) {
+        // optimise for loop using index access to avoid creating iterator 
object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
             if (notifier.isDisabled()) {
                 continue;
             }

Reply via email to