Skip to content

Commit 90bf666

Browse files
committed
corrected, unecessary walking of classes already present inside the hash table.
changed code so we avoid an extra lookup
1 parent 3b8a070 commit 90bf666

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

mono/metadata/unity-memory-info.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ ContextRecurseClassData (CollectMetadataContext *context, MonoClass *klass)
3636
* If we use g_hash_table_lookup it returns the value which we were comparing to NULL. The problem is
3737
* that 0 is a valid class index and was confusing our logic.
3838
*/
39-
if (!g_hash_table_lookup_extended (context->allTypes, klass, &orig_key, &value))
39+
if (!g_hash_table_lookup_extended (context->allTypes, klass, &orig_key, &value)) {
4040
g_hash_table_insert (context->allTypes, klass, GINT_TO_POINTER (context->currentIndex++));
4141

42-
fieldCount = mono_class_num_fields (klass);
43-
if (fieldCount > 0) {
44-
while ((field = mono_class_get_fields (klass, &iter))) {
45-
MonoClass *fieldKlass = mono_class_from_mono_type (field->type);
42+
fieldCount = mono_class_num_fields (klass);
43+
44+
if (fieldCount > 0) {
45+
while ((field = mono_class_get_fields (klass, &iter))) {
46+
MonoClass *fieldKlass = mono_class_from_mono_type (field->type);
4647

47-
if (!g_hash_table_lookup_extended (context->allTypes, fieldKlass, &orig_key, &value))
48-
ContextRecurseClassData (context, fieldKlass);
48+
if (fieldKlass != klass)
49+
ContextRecurseClassData (context, fieldKlass);
50+
}
4951
}
5052
}
5153
}

0 commit comments

Comments
 (0)