Change node_map type from map<ptr,ptr> to vector<pair<ptr,ptr>> (#386)
* Change node_map type from map<ptr,ptr> to vector<pair<ptr,ptr>> Map nodes are now iterated over in document order. * 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
f74ae543b4
commit
f0b15cd6a0
@ -114,7 +114,7 @@ class YAML_CPP_API node_data {
|
||||
mutable std::size_t m_seqSize;
|
||||
|
||||
// map
|
||||
typedef std::map<node*, node*> node_map;
|
||||
typedef std::vector<std::pair<node*, node*>> node_map;
|
||||
node_map m_map;
|
||||
|
||||
typedef std::pair<node*, node*> kv_pair;
|
||||
|
@ -37,7 +37,7 @@ struct node_iterator_value : public std::pair<V*, V*> {
|
||||
};
|
||||
|
||||
typedef std::vector<node*> node_seq;
|
||||
typedef std::map<node*, node*> node_map;
|
||||
typedef std::vector<std::pair<node*, node*>> node_map;
|
||||
|
||||
template <typename V>
|
||||
struct node_iterator_type {
|
||||
|
@ -256,9 +256,10 @@ void node_data::reset_map() {
|
||||
}
|
||||
|
||||
void node_data::insert_map_pair(node& key, node& value) {
|
||||
m_map[&key] = &value;
|
||||
m_map.emplace_back(&key, &value);
|
||||
|
||||
if (!key.is_defined() || !value.is_defined())
|
||||
m_undefinedPairs.push_back(kv_pair(&key, &value));
|
||||
m_undefinedPairs.emplace_back(&key, &value);
|
||||
}
|
||||
|
||||
void node_data::convert_to_map(shared_memory_holder pMemory) {
|
||||
|
@ -103,8 +103,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