mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
384e7e6b25
commit
6c76df4e10
1 changed files with 4 additions and 14 deletions
18
src/Type.cc
18
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<RecordType*>(t->AsRecordType());
|
||||
OptimizeCreationInits(rt);
|
||||
}
|
||||
OptimizeCreationInits(t->AsRecordType());
|
||||
|
||||
return detail::TC_CONTINUE;
|
||||
}
|
||||
|
@ -1176,7 +1166,7 @@ private:
|
|||
}
|
||||
|
||||
// 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue