diff --git a/src/Type.cc b/src/Type.cc index 0d9bd3e296..5626d28ed0 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1058,18 +1058,10 @@ EnumType::EnumType(const string& name) } EnumType::EnumType(const EnumType* e) - : BroType(TYPE_ENUM) + : BroType(TYPE_ENUM), names(e->names), vals(e->vals) { counter = e->counter; SetName(e->GetName()); - - for ( auto it = e->names.begin(); it != e->names.end(); ++it ) - names[it->first] = it->second; - - vals = e->vals; - - for ( auto& kv : vals ) - ::Ref(kv.second); } EnumType* EnumType::ShallowClone() @@ -1080,11 +1072,7 @@ EnumType* EnumType::ShallowClone() return new EnumType(this); } -EnumType::~EnumType() - { - for ( auto& kv : vals ) - Unref(kv.second); - } +EnumType::~EnumType() = default; // Note, we use reporter->Error() here (not Error()) to include the current script // location in the error message, rather than the one where the type was @@ -1157,7 +1145,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, AddNameInternal(module_name, name, val, is_export); if ( vals.find(val) == vals.end() ) - vals[val] = new EnumVal(this, val); + vals[val] = make_intrusive(this, val); set types = BroType::GetAliases(GetName()); set::const_iterator it; @@ -1209,17 +1197,17 @@ EnumType::enum_name_list EnumType::Names() const IntrusivePtr EnumType::GetVal(bro_int_t i) { auto it = vals.find(i); - EnumVal* rval; + IntrusivePtr rval; if ( it == vals.end() ) { - rval = new EnumVal(this, i); + rval = make_intrusive(this, i); vals[i] = rval; } else rval = it->second; - return {NewRef{}, rval}; + return rval; } void EnumType::DescribeReST(ODesc* d, bool roles_only) const diff --git a/src/Type.h b/src/Type.h index 7df8ae3057..44348f9e24 100644 --- a/src/Type.h +++ b/src/Type.h @@ -627,8 +627,6 @@ public: IntrusivePtr GetVal(bro_int_t i); protected: - EnumType() { counter = 0; } - void AddNameInternal(const std::string& module_name, const char* name, bro_int_t val, bool is_export); @@ -639,7 +637,7 @@ protected: typedef std::map NameMap; NameMap names; - using ValMap = std::unordered_map; + using ValMap = std::unordered_map>; ValMap vals; // The counter is initialized to 0 and incremented on every implicit diff --git a/src/Val.h b/src/Val.h index b897d5ec6e..56adccf3a8 100644 --- a/src/Val.h +++ b/src/Val.h @@ -924,16 +924,16 @@ protected: class EnumVal : public Val { public: + EnumVal(EnumType* t, int i) : Val(bro_int_t(i), t) + { + } + IntrusivePtr SizeVal() const override; protected: friend class Val; friend class EnumType; - EnumVal(EnumType* t, int i) : Val(bro_int_t(i), t) - { - } - void ValDescribe(ODesc* d) const override; IntrusivePtr DoClone(CloneState* state) override; };