camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/5] camel git commit: Optimise - Small optimisation in type converter and exchange
Date Sat, 24 Jun 2017 17:42:10 GMT
Repository: camel
Updated Branches:
  refs/heads/master 37544131a -> aeb71af0c


Optimise - Small optimisation in type converter and exchange


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

Branch: refs/heads/master
Commit: 79a1ae9ca01e4016a53fb8ed87af9f7f287938df
Parents: 3754413
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Jun 24 10:04:13 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Jun 24 10:10:00 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/impl/DefaultExchange.java |  8 ++++----
 .../impl/converter/BaseTypeConverterRegistry.java   | 16 ++++++++++------
 2 files changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/79a1ae9c/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
index 6b7a686..9888972 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
@@ -185,7 +185,7 @@ public final class DefaultExchange implements Exchange {
         Object value = getProperty(name);
         if (value == null) {
             // lets avoid NullPointerException when converting to boolean for null values
-            if (boolean.class.isAssignableFrom(type)) {
+            if (boolean.class == type || Boolean.class == type) {
                 return (T) Boolean.FALSE;
             }
             return null;
@@ -194,7 +194,7 @@ public final class DefaultExchange implements Exchange {
         // eager same instance type test to avoid the overhead of invoking the type converter
         // if already same type
         if (type.isInstance(value)) {
-            return type.cast(value);
+            return (T) value;
         }
 
         return ExchangeHelper.convertToType(this, type, value);
@@ -205,7 +205,7 @@ public final class DefaultExchange implements Exchange {
         Object value = getProperty(name, defaultValue);
         if (value == null) {
             // lets avoid NullPointerException when converting to boolean for null values
-            if (boolean.class.isAssignableFrom(type)) {
+            if (boolean.class == type || Boolean.class == type) {
                 return (T) Boolean.FALSE;
             }
             return null;
@@ -214,7 +214,7 @@ public final class DefaultExchange implements Exchange {
         // eager same instance type test to avoid the overhead of invoking the type converter
         // if already same type
         if (type.isInstance(value)) {
-            return type.cast(value);
+            return (T) value;
         }
 
         return ExchangeHelper.convertToType(this, type, value);

http://git-wip-us.apache.org/repos/asf/camel/blob/79a1ae9c/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
b/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
index 6e4a1b1..28d9caf1 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
@@ -256,7 +256,7 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport
implement
                 noopCounter.increment();
             }
             // lets avoid NullPointerException when converting to boolean for null values
-            if (boolean.class.isAssignableFrom(type)) {
+            if (boolean.class == type || Boolean.class == type) {
                 return Boolean.FALSE;
             }
             return null;
@@ -760,10 +760,18 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport
implement
     protected static final class TypeMapping {
         private final Class<?> toType;
         private final Class<?> fromType;
+        private final int hashCode;
 
         TypeMapping(Class<?> toType, Class<?> fromType) {
             this.toType = toType;
             this.fromType = fromType;
+
+            // pre calculate hashcode
+            int hash = toType.hashCode();
+            if (fromType != null) {
+                hash *= 37 + fromType.hashCode();
+            }
+            hashCode = hash;
         }
 
         public Class<?> getFromType() {
@@ -785,11 +793,7 @@ public abstract class BaseTypeConverterRegistry extends ServiceSupport
implement
 
         @Override
         public int hashCode() {
-            int answer = toType.hashCode();
-            if (fromType != null) {
-                answer *= 37 + fromType.hashCode();
-            }
-            return answer;
+            return hashCode;
         }
 
         @Override


Mime
View raw message