Change insert_map_pair to always append
Always append in insert_map_pair even if the key is already present. This breaks the behavior of force_insert which now always inserts KVs even if the key is already present. The first insert for duplicated keys now takes precedence for lookups.
This commit is contained in:
parent
f327b19e93
commit
3213df1ac6
@ -256,18 +256,7 @@ void node_data::reset_map() {
|
||||
}
|
||||
|
||||
void node_data::insert_map_pair(node& key, node& value) {
|
||||
|
||||
bool found = false;
|
||||
for (auto& entry : m_map) {
|
||||
if (entry.first == &key) {
|
||||
entry.second = &value;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
m_map.emplace_back(&key, &value);
|
||||
}
|
||||
m_map.emplace_back(&key, &value);
|
||||
|
||||
if (!key.is_defined() || !value.is_defined())
|
||||
m_undefinedPairs.emplace_back(&key, &value);
|
||||
|
||||
@ -95,8 +95,8 @@ TEST(NodeTest, MapForceInsert) {
|
||||
|
||||
node.force_insert(k2, v2);
|
||||
EXPECT_EQ("v1", node["k1"].as<std::string>());
|
||||
EXPECT_EQ("v2", node["k2"].as<std::string>());
|
||||
EXPECT_EQ(2, node.size());
|
||||
EXPECT_EQ("v1", node["k2"].as<std::string>());
|
||||
EXPECT_EQ(3, node.size());
|
||||
}
|
||||
|
||||
TEST(NodeTest, UndefinedConstNodeWithFallback) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user