You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2018/07/26 16:15:39 UTC

[camel] 04/05: [CAMEL-12688] Improve introspection performances

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

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

commit 7af620666722660db19f98ce18b7685b57be5c9a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jun 25 15:22:58 2018 +0200

    [CAMEL-12688] Improve introspection performances
---
 .../org/apache/camel/util/IntrospectionSupport.java | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 5445816..008c6e1 100644
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -308,6 +308,8 @@ public final class IntrospectionSupport {
         // especially about getter/setters
         List<MethodInfo> found = new ArrayList<>();
         Method[] methods = clazz.getMethods();
+        Map<String, MethodInfo> getters = new HashMap<>(methods.length);
+        Map<String, MethodInfo> setters = new HashMap<>(methods.length);
         for (Method method : methods) {
             if (EXCLUDED_METHODS.contains(method)) {
                 continue;
@@ -319,14 +321,15 @@ public final class IntrospectionSupport {
                 cache.isGetter = true;
                 cache.isSetter = false;
                 cache.getterOrSetterShorthandName = getGetterShorthandName(method);
+                getters.put(cache.getterOrSetterShorthandName, cache);
             } else if (isSetter(method)) {
                 cache.isGetter = false;
                 cache.isSetter = true;
                 cache.getterOrSetterShorthandName = getSetterShorthandName(method);
+                setters.put(cache.getterOrSetterShorthandName, cache);
             } else {
                 cache.isGetter = false;
                 cache.isSetter = false;
-                cache.hasGetterAndSetter = false;
             }
             found.add(cache);
         }
@@ -336,21 +339,9 @@ public final class IntrospectionSupport {
         for (MethodInfo info : found) {
             info.hasGetterAndSetter = false;
             if (info.isGetter) {
-                // loop and find the matching setter
-                for (MethodInfo info2 : found) {
-                    if (info2.isSetter && info.getterOrSetterShorthandName.equals(info2.getterOrSetterShorthandName)) {
-                        info.hasGetterAndSetter = true;
-                        break;
-                    }
-                }
+                info.hasGetterAndSetter = setters.containsKey(info.getterOrSetterShorthandName);
             } else if (info.isSetter) {
-                // loop and find the matching getter
-                for (MethodInfo info2 : found) {
-                    if (info2.isGetter && info.getterOrSetterShorthandName.equals(info2.getterOrSetterShorthandName)) {
-                        info.hasGetterAndSetter = true;
-                        break;
-                    }
-                }
+                info.hasGetterAndSetter = getters.containsKey(info.getterOrSetterShorthandName);
             }
         }