You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/10/26 16:54:18 UTC

[camel] branch master updated: camel-core - Optimize type converter a little bit

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


The following commit(s) were added to refs/heads/master by this push:
     new 5e56561  camel-core - Optimize type converter a little bit
5e56561 is described below

commit 5e565614219d2089c73cd4cfaffd1a6c1fc131c4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Oct 26 17:24:00 2020 +0100

    camel-core - Optimize type converter a little bit
---
 .../impl/converter/CoreTypeConverterRegistry.java  | 42 ++++++++++++++++------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java b/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java
index bb7a63c..e0830c4 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java
@@ -139,10 +139,21 @@ public class CoreTypeConverterRegistry extends ServiceSupport implements TypeCon
             } else if (type == Boolean.class && (value instanceof String)) {
                 // String -> Boolean
                 String str = (String) value;
-                if ("true".equalsIgnoreCase(str)) {
+                // must be 4 or 5 in length
+                int len = str.length();
+                // fast check the value as-is in lower case which is most common
+                if (len == 4 && "true".equals(str)) {
                     return (T) Boolean.TRUE;
-                } else if ("false".equalsIgnoreCase(str)) {
+                } else if (len == 5 && "false".equals(str)) {
                     return (T) Boolean.FALSE;
+                } else {
+                    // do check for ignore case
+                    str = str.toUpperCase();
+                    if (len == 4 && "TRUE".equals(str)) {
+                        return (T) Boolean.TRUE;
+                    } else if (len == 5 && "FALSE".equals(str)) {
+                        return (T) Boolean.FALSE;
+                    }
                 }
             } else if (type.isPrimitive()) {
                 // okay its a wrapper -> primitive then return as-is for some common types
@@ -154,9 +165,9 @@ public class CoreTypeConverterRegistry extends ServiceSupport implements TypeCon
                 // okay its a primitive -> string then return as-is for some common types
                 Class<?> cls = value.getClass();
                 if (cls.isPrimitive()
-                        || cls == Boolean.class || cls == boolean.class
-                        || cls == Integer.class || cls == int.class
-                        || cls == Long.class || cls == long.class) {
+                        || cls == Boolean.class
+                        || cls == Integer.class
+                        || cls == Long.class) {
                     return (T) value.toString();
                 }
             }
@@ -190,10 +201,21 @@ public class CoreTypeConverterRegistry extends ServiceSupport implements TypeCon
             } else if (type == Boolean.class && (value instanceof String)) {
                 // String -> Boolean
                 String str = (String) value;
-                if ("true".equalsIgnoreCase(str)) {
+                // must be 4 or 5 in length
+                int len = str.length();
+                // fast check the value as-is in lower case which is most common
+                if (len == 4 && "true".equals(str)) {
                     return (T) Boolean.TRUE;
-                } else if ("false".equalsIgnoreCase(str)) {
+                } else if (len == 5 && "false".equals(str)) {
                     return (T) Boolean.FALSE;
+                } else {
+                    // do check for ignore case
+                    str = str.toUpperCase();
+                    if (len == 4 && "TRUE".equals(str)) {
+                        return (T) Boolean.TRUE;
+                    } else if (len == 5 && "FALSE".equals(str)) {
+                        return (T) Boolean.FALSE;
+                    }
                 }
             } else if (type.isPrimitive()) {
                 // okay its a wrapper -> primitive then return as-is for some common types
@@ -205,9 +227,9 @@ public class CoreTypeConverterRegistry extends ServiceSupport implements TypeCon
                 // okay its a primitive -> string then return as-is for some common types
                 Class<?> cls = value.getClass();
                 if (cls.isPrimitive()
-                        || cls == Boolean.class || cls == boolean.class
-                        || cls == Integer.class || cls == int.class
-                        || cls == Long.class || cls == long.class) {
+                        || cls == Boolean.class
+                        || cls == Integer.class
+                        || cls == Long.class) {
                     return (T) value.toString();
                 }
             }