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*`...
This commit is contained in:
Arne Welzel 2023-09-12 20:21:42 +02:00
parent 384e7e6b25
commit 6c76df4e10

View file

@ -1132,26 +1132,16 @@ private:
class RecordType::CreationInitsOptimizer : public detail::TraversalCallback class RecordType::CreationInitsOptimizer : public detail::TraversalCallback
{ {
public: public:
detail::TraversalCode PreID(const detail::ID* id) override detail::TraversalCode PreTypedef(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
{ {
const auto& t = id->GetType();
if ( analyzed_types.count(t) > 0 ) if ( analyzed_types.count(t) > 0 )
return detail::TC_ABORTSTMT; return detail::TC_ABORTSTMT;
analyzed_types.emplace(t); analyzed_types.emplace(t);
if ( t->Tag() == TYPE_RECORD ) if ( t->Tag() == TYPE_RECORD )
{ OptimizeCreationInits(t->AsRecordType());
auto* rt = const_cast<RecordType*>(t->AsRecordType());
OptimizeCreationInits(rt);
}
return detail::TC_CONTINUE; return detail::TC_CONTINUE;
} }
@ -1176,7 +1166,7 @@ private:
} }
// Endless recursion avoidance. // Endless recursion avoidance.
std::unordered_set<const Type*> analyzed_types; std::unordered_set<TypePtr> analyzed_types;
}; };
RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD) RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD)