diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp index 01f4e1cbc65..6ee94d35d65 100644 --- a/src/ir/module-utils.cpp +++ b/src/ir/module-utils.cpp @@ -363,8 +363,15 @@ struct TypeInfos { } } void note(Type type) { - for (HeapType ht : type.getHeapTypeChildren()) { - note(ht); + // Handle the common case of a ref directly, to avoid a scan of children. + if (type.isRef()) { + note(type.getHeapType()); + return; + } + if (type.isTuple()) { + for (HeapType ht : type.getHeapTypeChildren()) { + note(ht); + } } } // Ensure a type is included without increasing its count. @@ -374,8 +381,14 @@ struct TypeInfos { } } void include(Type type) { - for (HeapType ht : type.getHeapTypeChildren()) { - include(ht); + if (type.isRef()) { + include(type.getHeapType()); + return; + } + if (type.isTuple()) { + for (HeapType ht : type.getHeapTypeChildren()) { + include(ht); + } } } void noteControlFlow(Signature sig) {