From 7fbdf384deb92d7f6907b771596fde67cf56efff Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 21 Oct 2019 01:07:38 -0400 Subject: [PATCH] Console: Reuse iterator in unregisterCommand() We can use the result of the first lookup to avoid doing another redundant lookup to perform the erasure. While we're at it, we can use std::string's std::string_view constructor in order to avoid an unnecessary strlen() call. --- hecl/lib/Console.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hecl/lib/Console.cpp b/hecl/lib/Console.cpp index f4d73a455..c1828c65c 100644 --- a/hecl/lib/Console.cpp +++ b/hecl/lib/Console.cpp @@ -54,10 +54,15 @@ void Console::registerCommand(std::string_view name, std::string_view helpText, } void Console::unregisterCommand(std::string_view name) { - std::string lowName = name.data(); + std::string lowName{name}; athena::utility::tolower(lowName); - if (m_commands.find(lowName) != m_commands.end()) - m_commands.erase(m_commands.find(lowName)); + + const auto iter = m_commands.find(lowName); + if (iter == m_commands.end()) { + return; + } + + m_commands.erase(iter); } void Console::executeString(const std::string& str) {