Avoid type unnecessary type conversion in ComponentManager::GetComponentName

This commit is contained in:
Tim Wojtulewicz 2022-05-10 12:50:53 -07:00
parent 1f8d406658
commit 22ab3bb0b3

View file

@ -13,6 +13,7 @@
#include "zeek/Type.h" #include "zeek/Type.h"
#include "zeek/Val.h" #include "zeek/Val.h"
#include "zeek/Var.h" // for add_type() #include "zeek/Var.h" // for add_type()
#include "zeek/ZeekString.h"
#include "zeek/module_util.h" #include "zeek/module_util.h"
#include "zeek/zeekygen/Manager.h" #include "zeek/zeekygen/Manager.h"
@ -193,9 +194,7 @@ template <class C> const std::string& ComponentManager<C>::GetComponentName(zeek
if ( ! tag ) if ( ! tag )
return error; return error;
C* c = Lookup(tag); if ( C* c = Lookup(tag) )
if ( c )
return c->CanonicalName(); return c->CanonicalName();
reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str()); reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str());
@ -204,7 +203,17 @@ template <class C> const std::string& ComponentManager<C>::GetComponentName(zeek
template <class C> const std::string& ComponentManager<C>::GetComponentName(EnumValPtr val) const template <class C> const std::string& ComponentManager<C>::GetComponentName(EnumValPtr val) const
{ {
return GetComponentName(zeek::Tag(std::move(val))); static const std::string error = "<error>";
if ( ! val )
return error;
if ( C* c = Lookup(val.get()) )
return c->CanonicalName();
reporter->InternalWarning("requested name of unknown component tag %s",
val->AsString()->CheckString());
return error;
} }
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(const std::string& name) const template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(const std::string& name) const