From 6c76df4e10f86563124d92110c93292b0efccfc1 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 12 Sep 2023 20:21:42 +0200 Subject: [PATCH] CreationInitsOptimizer: Use PreTypedef() instead of PreType() PreTypedef() does not require the PreID() trampoline and ensures it's only called for IDs that are types. Also allows dropping the const_cast<> due to id->GetType() returning a const TypePtr which is different from a `const Type*`... --- src/Type.cc | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index 5377b602de..4d638901d9 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1132,26 +1132,16 @@ private: class RecordType::CreationInitsOptimizer : public detail::TraversalCallback { public: - detail::TraversalCode PreID(const detail::ID* id) override - { - if ( const auto& t = id->GetType() ) - HANDLE_TC_TYPE_POST(t->Traverse(this)); - - return detail::TC_CONTINUE; - } - - detail::TraversalCode PreType(const Type* t) override + detail::TraversalCode PreTypedef(const detail::ID* id) override { + const auto& t = id->GetType(); if ( analyzed_types.count(t) > 0 ) return detail::TC_ABORTSTMT; analyzed_types.emplace(t); if ( t->Tag() == TYPE_RECORD ) - { - auto* rt = const_cast(t->AsRecordType()); - OptimizeCreationInits(rt); - } + OptimizeCreationInits(t->AsRecordType()); return detail::TC_CONTINUE; } @@ -1176,7 +1166,7 @@ private: } // Endless recursion avoidance. - std::unordered_set analyzed_types; + std::unordered_set analyzed_types; }; RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD)