mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Switched memory to using shared nodes, and node_data to keep only naked node pointers, not shared nodes (to break the cycle, and we don't need weak pointers because their memory is guaranteed to exist, via 'memory')
This commit is contained in:
@@ -14,11 +14,11 @@ namespace YAML
|
||||
rhs.m_pMemory = m_pMemory;
|
||||
}
|
||||
|
||||
shared_node memory::create_node()
|
||||
node& memory::create_node()
|
||||
{
|
||||
shared_node_ref pRef(new node_ref);
|
||||
m_nodes.insert(pRef);
|
||||
return shared_node(new node(pRef));
|
||||
shared_node pNode(new node);
|
||||
m_nodes.insert(pNode);
|
||||
return *pNode;
|
||||
}
|
||||
|
||||
void memory::merge(const memory& rhs)
|
||||
|
@@ -58,20 +58,20 @@ namespace YAML
|
||||
}
|
||||
|
||||
// indexing
|
||||
shared_node node_data::get(shared_node pKey, shared_memory_holder pMemory) const
|
||||
node& node_data::get(node& key, shared_memory_holder pMemory) const
|
||||
{
|
||||
if(m_type != ValueType::Map)
|
||||
return pMemory->create_node();
|
||||
|
||||
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||
if(it->first == pKey)
|
||||
return it->second;
|
||||
if(it->first == &key) // TODO: equality?
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
return pMemory->create_node();
|
||||
}
|
||||
|
||||
shared_node node_data::get(shared_node pKey, shared_memory_holder pMemory)
|
||||
node& node_data::get(node& key, shared_memory_holder pMemory)
|
||||
{
|
||||
switch(m_type) {
|
||||
case ValueType::Undefined:
|
||||
@@ -88,22 +88,22 @@ namespace YAML
|
||||
}
|
||||
|
||||
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||
if(it->first == pKey)
|
||||
return it->second;
|
||||
if(it->first == &key) // TODO: equality?
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
shared_node pValue = pMemory->create_node();
|
||||
m_map.push_back(kv_pair(pKey, pValue));
|
||||
return pValue;
|
||||
node& value = pMemory->create_node();
|
||||
m_map.push_back(kv_pair(&key, &value));
|
||||
return value;
|
||||
}
|
||||
|
||||
bool node_data::remove(shared_node pKey, shared_memory_holder /* pMemory */)
|
||||
bool node_data::remove(node& key, shared_memory_holder /* pMemory */)
|
||||
{
|
||||
if(m_type != ValueType::Map)
|
||||
return false;
|
||||
|
||||
for(node_map::iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||
if(it->first == pKey) {
|
||||
if(it->first == &key) { // TODO: equality?
|
||||
m_map.erase(it);
|
||||
return true;
|
||||
}
|
||||
@@ -121,9 +121,9 @@ namespace YAML
|
||||
std::stringstream stream;
|
||||
stream << i;
|
||||
|
||||
shared_node pKey = pMemory->create_node();
|
||||
pKey->set_scalar(stream.str());
|
||||
m_map.push_back(kv_pair(pKey, m_sequence[i]));
|
||||
node& key = pMemory->create_node();
|
||||
key.set_scalar(stream.str());
|
||||
m_map.push_back(kv_pair(&key, m_sequence[i]));
|
||||
}
|
||||
|
||||
m_sequence.clear();
|
||||
|
Reference in New Issue
Block a user