[Lldb-commits] [lldb] [lldb] Avoid repeated map lookups (NFC) (PR #112315)

Kazu Hirata via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 14 23:23:00 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112315

None

>From 70d0a4b3ce6445dd182225df09aecf450b4073ec Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 14 Oct 2024 23:11:09 -0700
Subject: [PATCH] [lldb] Avoid repeated map lookups (NFC)

---
 lldb/source/Commands/CommandObjectMultiword.cpp | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp
index 4efa5652a71703..8e9f91c64140ea 100644
--- a/lldb/source/Commands/CommandObjectMultiword.cpp
+++ b/lldb/source/Commands/CommandObjectMultiword.cpp
@@ -84,16 +84,7 @@ bool CommandObjectMultiword::LoadSubCommand(llvm::StringRef name,
     lldbassert((&GetCommandInterpreter() == &cmd_obj_sp->GetCommandInterpreter()) &&
            "tried to add a CommandObject from a different interpreter");
 
-  CommandMap::iterator pos;
-  bool success = true;
-
-  pos = m_subcommand_dict.find(std::string(name));
-  if (pos == m_subcommand_dict.end()) {
-    m_subcommand_dict[std::string(name)] = cmd_obj_sp;
-  } else
-    success = false;
-
-  return success;
+  return m_subcommand_dict.try_emplace(std::string(name), cmd_obj_sp).second;
 }
 
 llvm::Error CommandObjectMultiword::LoadUserSubcommand(



More information about the lldb-commits mailing list