You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/07/05 15:35:59 UTC

[groovy] branch GROOVY-9620 created (now 354e83e)

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

emilles pushed a change to branch GROOVY-9620
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 354e83e  GROOVY-9620: do not loop over findPropertyInClassHierarchy

This branch includes the following new commits:

     new 354e83e  GROOVY-9620: do not loop over findPropertyInClassHierarchy

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: GROOVY-9620: do not loop over findPropertyInClassHierarchy

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-9620
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 354e83eedc3f67db48eff0e60a4a695475762fa5
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Jul 5 10:34:50 2020 -0500

    GROOVY-9620: do not loop over findPropertyInClassHierarchy
---
 src/main/java/groovy/lang/MetaClassImpl.java | 43 ++++++++++++----------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 63f95d3..7324b14 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -290,15 +290,10 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 propertyMap = classPropertyIndexForSuper.getNotNull(theCachedClass);
                 metaProperty = (MetaProperty) propertyMap.get(name);
                 if (metaProperty == null) {
-                    CachedClass superClass = theCachedClass;
-                    while (superClass != null && superClass != ReflectionCache.OBJECT_CLASS) {
-                        MetaBeanProperty property = findPropertyInClassHierarchy(name, superClass);
-                        if (property != null) {
-                            onSuperPropertyFoundInHierarchy(property);
-                            metaProperty = property;
-                            break;
-                        }
-                        superClass = superClass.getCachedSuperClass();
+                    MetaBeanProperty property = findPropertyInClassHierarchy(name, theCachedClass);
+                    if (property != null) {
+                        onSuperPropertyFoundInHierarchy(property);
+                        metaProperty = property;
                     }
                 }
             }
@@ -840,21 +835,17 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
      * @return The result of the method invocation.
      */
     public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) {
-        Class theClass = instance instanceof Class ? (Class) instance : instance.getClass();
-        CachedClass superClass = theCachedClass;
-        while (superClass != null && superClass != ReflectionCache.OBJECT_CLASS) {
-            final MetaBeanProperty property = findPropertyInClassHierarchy(propertyName, superClass);
-            if (property != null) {
-                onSuperPropertyFoundInHierarchy(property);
-                if (!isGetter) {
-                    property.setProperty(instance, optionalValue);
-                    return null;
-                }
-                return property.getProperty(instance);
+        MetaBeanProperty property = findPropertyInClassHierarchy(propertyName, theCachedClass);
+        if (property != null) {
+            onSuperPropertyFoundInHierarchy(property);
+            if (!isGetter) {
+                property.setProperty(instance, optionalValue);
+                return null;
             }
-            superClass = superClass.getCachedSuperClass();
+            return property.getProperty(instance);
         }
-        // got here to property not found, look for getProperty or setProperty overrides
+
+        // look for getProperty or setProperty overrides
         if (isGetter) {
             final Class[] getPropertyArgs = {String.class};
             final MetaMethod method = findMethodInClassHierarchy(instance.getClass(), GET_PROPERTY_METHOD, getPropertyArgs, this);
@@ -892,6 +883,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
             throw iie;
         }
 
+        Class theClass = instance instanceof Class ? (Class) instance : instance.getClass();
         if (instance instanceof Class && theClass != Class.class) {
             final MetaProperty metaProperty = InvokerHelper.getMetaClass(Class.class).hasProperty(instance, propertyName);
             if (metaProperty != null) {
@@ -902,6 +894,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 return null;
             }
         }
+
         throw new MissingPropertyExceptionNoStack(propertyName, theClass);
     }
 
@@ -3605,14 +3598,15 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
     }
 
     protected MetaBeanProperty findPropertyInClassHierarchy(String propertyName, CachedClass theClass) {
-        MetaBeanProperty property = null;
-        if (theClass == null)
+        if (theClass == null || theClass == ReflectionCache.OBJECT_CLASS)
             return null;
 
         final CachedClass superClass = theClass.getCachedSuperClass();
         if (superClass == null)
             return null;
 
+        MetaBeanProperty property = null;
+
         MetaClass metaClass = this.registry.getMetaClass(superClass.getTheClass());
         if (metaClass instanceof MutableMetaClass) {
             property = getMetaPropertyFromMutableMetaClass(propertyName, metaClass);
@@ -3627,7 +3621,6 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
             }
         }
         return property;
-
     }
 
     private MetaBeanProperty searchInterfacesForMetaProperty(String propertyName, Class[] interfaces) {