[runtime] Faster parent check in ves_icall_System_Reflection_FieldInfo_internal_from_...
authorAleksey Kliger <aleksey@xamarin.com>
Thu, 14 Jul 2016 18:39:01 +0000 (14:39 -0400)
committerAleksey Kliger <aleksey@xamarin.com>
Thu, 14 Jul 2016 19:19:57 +0000 (15:19 -0400)
Use mono_class_has_parent for a faster supertypes check instead of
following the parent pointers.

mono/metadata/icall.c

index c3dd869958e1016950ab9aca78095f8756117700..b48e23bcfe19edf2f745cfd776046a0faf314b48 100644 (file)
@@ -1765,7 +1765,6 @@ ves_icall_System_Reflection_FieldInfo_internal_from_handle_type (MonoClassField
        MonoError error;
        gboolean found = FALSE;
        MonoClass *klass;
-       MonoClass *k;
 
        g_assert (handle);
 
@@ -1774,13 +1773,7 @@ ves_icall_System_Reflection_FieldInfo_internal_from_handle_type (MonoClassField
        } else {
                klass = mono_class_from_mono_type (type);
 
-               /* Check that the field belongs to the class */
-               for (k = klass; k; k = k->parent) {
-                       if (k == handle->parent) {
-                               found = TRUE;
-                               break;
-                       }
-               }
+               found = klass == handle->parent || mono_class_has_parent (klass, handle->parent);
 
                if (!found)
                        /* The managed code will throw the exception */