diff --git a/src/developer/debug/zxdb/symbols/index_test_support.cc b/src/developer/debug/zxdb/symbols/index_test_support.cc index 751b9f7a7e0a87bdd0b27df258df21668e022ad0..3ad2fd4faa3b3a5066dcca346cca14497188e7c1 100644 --- a/src/developer/debug/zxdb/symbols/index_test_support.cc +++ b/src/developer/debug/zxdb/symbols/index_test_support.cc @@ -36,7 +36,7 @@ TestIndexedSymbol::TestIndexedSymbol(MockModuleSymbols* mod_sym, const std::string& name, fxl::RefPtr<Symbol> sym) : die_ref(RefTypeForSymbol(sym), next_die_ref++), - index_node(index_parent->AddChild(std::string(name))), + index_node(index_parent->AddChild(name)), symbol(std::move(sym)) { index_node->AddDie(die_ref); mod_sym->AddDieRef(die_ref, symbol); diff --git a/src/developer/debug/zxdb/symbols/module_symbol_index_node.cc b/src/developer/debug/zxdb/symbols/module_symbol_index_node.cc index 16d736b1b2749b1a35fd20f960c19beafd806a33..aa5eab0eda7b0f68b0f5cec294ec7e6b20b04bf1 100644 --- a/src/developer/debug/zxdb/symbols/module_symbol_index_node.cc +++ b/src/developer/debug/zxdb/symbols/module_symbol_index_node.cc @@ -78,7 +78,7 @@ void ModuleSymbolIndexNode::AddDie(const DieRef& ref) { dies_.push_back(ref); } -ModuleSymbolIndexNode* ModuleSymbolIndexNode::AddChild(std::string&& name) { +ModuleSymbolIndexNode* ModuleSymbolIndexNode::AddChild(std::string name) { return &sub_.emplace(std::piecewise_construct, std::forward_as_tuple(std::move(name)), std::forward_as_tuple()) @@ -92,13 +92,16 @@ ModuleSymbolIndexNode* ModuleSymbolIndexNode::AddChild(const char* name) { .first->second; } -void ModuleSymbolIndexNode::AddChild( - std::pair<std::string, ModuleSymbolIndexNode>&& child) { - auto existing = sub_.find(child.first); - if (existing == sub_.end()) - sub_.emplace(std::move(child)); - else - existing->second.Merge(std::move(child.second)); +void ModuleSymbolIndexNode::AddChild(const std::string& name, + ModuleSymbolIndexNode&& child) { + auto existing = sub_.find(name); + if (existing == sub_.end()) { + sub_.emplace(std::piecewise_construct, + std::forward_as_tuple(name), + std::forward_as_tuple(std::move(child))); + } else { + existing->second.Merge(std::move(child)); + } } void ModuleSymbolIndexNode::Merge(ModuleSymbolIndexNode&& other) { diff --git a/src/developer/debug/zxdb/symbols/module_symbol_index_node.h b/src/developer/debug/zxdb/symbols/module_symbol_index_node.h index 92344e4cd4c282a2f21bd35336681bae794174a5..c1c37890a610450f9e4c1f33d5691399df639acc 100644 --- a/src/developer/debug/zxdb/symbols/module_symbol_index_node.h +++ b/src/developer/debug/zxdb/symbols/module_symbol_index_node.h @@ -108,6 +108,10 @@ class ModuleSymbolIndexNode { // Makes a node pointing to one DIE. explicit ModuleSymbolIndexNode(const DieRef& ref); + // Move-only. + ModuleSymbolIndexNode(ModuleSymbolIndexNode&&) = default; + ModuleSymbolIndexNode(const ModuleSymbolIndexNode&) = delete; + ~ModuleSymbolIndexNode(); bool empty() const { return sub_.empty() && dies_.empty(); } @@ -136,12 +140,12 @@ class ModuleSymbolIndexNode { // needed upon insertion is slightly faster than creating a std::string and // passing it in. Use the char* version if the source string is a // null-terminated C-string. - ModuleSymbolIndexNode* AddChild(std::string&& name); + ModuleSymbolIndexNode* AddChild(std::string name); ModuleSymbolIndexNode* AddChild(const char* name); // Adds a child to this node. If a node with this key already exists in this // node, they will be merged. - void AddChild(std::pair<std::string, ModuleSymbolIndexNode>&& child); + void AddChild(const std::string& name, ModuleSymbolIndexNode&& child); // Merges another node's children into this one. It's assumed there are no // duplicate DIEs so the lists are just appended. diff --git a/src/developer/debug/zxdb/symbols/module_symbol_index_node_unittest.cc b/src/developer/debug/zxdb/symbols/module_symbol_index_node_unittest.cc index 567cf247d8f166722f431505e99e546321164e26..a4063194d12e86805f684f95d84c44e7e249d8e1 100644 --- a/src/developer/debug/zxdb/symbols/module_symbol_index_node_unittest.cc +++ b/src/developer/debug/zxdb/symbols/module_symbol_index_node_unittest.cc @@ -109,11 +109,11 @@ TEST(ModuleSymbolIndexNode, AddChildMerge) { ModuleSymbolIndexNode node1; node1.AddDie(DieRef(RefType::kFunction, offset1)); - node1.AddChild(std::make_pair(bar, std::move(node2))); + node1.AddChild(bar, std::move(node2)); ModuleSymbolIndexNode root; EXPECT_TRUE(root.empty()); - root.AddChild(std::make_pair(foo, std::move(node1))); + root.AddChild(foo, std::move(node1)); EXPECT_FALSE(root.empty()); // The merged one has the hierarchy: @@ -124,10 +124,10 @@ TEST(ModuleSymbolIndexNode, AddChildMerge) { ModuleSymbolIndexNode merge1; merge1.AddDie(DieRef(RefType::kFunction, offset3)); - merge1.AddChild(std::make_pair(bloop, std::move(merge2))); + merge1.AddChild(bloop, std::move(merge2)); // Now merge in "merge1" as a child of the root. - root.AddChild(std::make_pair(foo, std::move(merge1))); + root.AddChild(foo, std::move(merge1)); // This should merge the two to get: // [root]