From 0f17bd068733c122c5c80f0b9a1dfb6e7f37203c Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Thu, 1 Jul 2021 12:06:35 +0200 Subject: [PATCH] Improve Table copy assignment operator --- src/table.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/table.cpp b/src/table.cpp index 6c538b8..614aec0 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -67,8 +67,10 @@ Table &Table::operator=(const Table &table) // loop through the table records for (auto iter = table._fields.begin(); iter != table._fields.end(); iter++) { - // add the field - _fields[iter->first] = std::shared_ptr(iter->second->clone()); + // since a map is always ordered, we know that each element will + // be inserted at the end of the new map, so we can simply use + // emplace_hint and hint at insertion at the end of the map + _fields.insert(_fields.end(), std::make_pair(iter->first, iter->second->clone())); } // done