From 22ab3bb0b349af4e4f3c943e975f5e33495d3ab4 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 10 May 2022 12:50:53 -0700 Subject: [PATCH] Avoid type unnecessary type conversion in ComponentManager::GetComponentName --- src/plugin/ComponentManager.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index f2485ecad8..3021982040 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -13,6 +13,7 @@ #include "zeek/Type.h" #include "zeek/Val.h" #include "zeek/Var.h" // for add_type() +#include "zeek/ZeekString.h" #include "zeek/module_util.h" #include "zeek/zeekygen/Manager.h" @@ -193,9 +194,7 @@ template const std::string& ComponentManager::GetComponentName(zeek if ( ! tag ) return error; - C* c = Lookup(tag); - - if ( c ) + if ( C* c = Lookup(tag) ) return c->CanonicalName(); reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str()); @@ -204,7 +203,17 @@ template const std::string& ComponentManager::GetComponentName(zeek template const std::string& ComponentManager::GetComponentName(EnumValPtr val) const { - return GetComponentName(zeek::Tag(std::move(val))); + static const std::string 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 zeek::Tag ComponentManager::GetComponentTag(const std::string& name) const