- don't leak node in both hash_table::bucket::erase()
- remove bad code from hash_table::bucket::erase(const char *) that was introduced with the last patch. (This function isn't used anywhere and is scheduled for removal. Leaving it in for now as a reference.) - remove leaves first in remove_from_path_caches() - cosmetics: indentation, one trailing space, variable name change, comment (Sorrry for mixing that with actual code, but I think it's easy to see.)
This commit is contained in:
+12
-11
@@ -911,17 +911,18 @@ SGPropertyNode::getChildren (const char * name) const
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove this node from all nodes that link to it in their path cache.
|
* Remove this node and all children from nodes that link to them
|
||||||
|
* in their path cache.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
SGPropertyNode::remove_from_path_caches ()
|
SGPropertyNode::remove_from_path_caches ()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < _linkedNodes.size(); i++)
|
|
||||||
_linkedNodes[i]->erase(this);
|
|
||||||
|
|
||||||
_linkedNodes.clear();
|
|
||||||
for (unsigned int i = 0; i < _children.size(); ++i)
|
for (unsigned int i = 0; i < _children.size(); ++i)
|
||||||
_children[i]->remove_from_path_caches();
|
_children[i]->remove_from_path_caches();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < _linkedNodes.size(); i++)
|
||||||
|
_linkedNodes[i]->erase(this);
|
||||||
|
_linkedNodes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2236,10 +2237,11 @@ SGPropertyNode::hash_table::bucket::erase (const char * key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i < _length) {
|
if (i < _length) {
|
||||||
|
delete _entries[i];
|
||||||
for (++i; i < _length; i++) {
|
for (++i; i < _length; i++) {
|
||||||
_entries[i-1] = _entries[i];
|
_entries[i-1] = _entries[i];
|
||||||
}
|
}
|
||||||
_length--;
|
_length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2248,6 +2250,7 @@ SGPropertyNode::hash_table::bucket::erase (SGPropertyNode * node)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < _length; i++) {
|
for (int i = 0; i < _length; i++) {
|
||||||
if (_entries[i]->get_value() == node) {
|
if (_entries[i]->get_value() == node) {
|
||||||
|
delete _entries[i];
|
||||||
for (++i; i < _length; i++) {
|
for (++i; i < _length; i++) {
|
||||||
_entries[i-1] = _entries[i];
|
_entries[i-1] = _entries[i];
|
||||||
}
|
}
|
||||||
@@ -2307,21 +2310,19 @@ SGPropertyNode::hash_table::put (const char * key, SGPropertyNode * value)
|
|||||||
void
|
void
|
||||||
SGPropertyNode::hash_table::erase (const char * key)
|
SGPropertyNode::hash_table::erase (const char * key)
|
||||||
{
|
{
|
||||||
if (_data_length == 0)
|
if (_data_length == 0)
|
||||||
return;
|
return;
|
||||||
unsigned int index = hashcode(key) % _data_length;
|
unsigned int index = hashcode(key) % _data_length;
|
||||||
if (_data[index] == 0)
|
if (_data[index] == 0)
|
||||||
return;
|
return;
|
||||||
_data[index]->get_entry(key, true)->get_value()->remove_linked_node(this);
|
|
||||||
_data[index]->erase(key);
|
_data[index]->erase(key);
|
||||||
_data[index] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SGPropertyNode::hash_table::erase (SGPropertyNode * node)
|
SGPropertyNode::hash_table::erase (SGPropertyNode * node)
|
||||||
{
|
{
|
||||||
for (unsigned int d = 0; d < _data_length; d++)
|
for (unsigned int i = 0; i < _data_length; i++)
|
||||||
if (_data[d] && _data[d]->erase(node))
|
if (_data[i] && _data[i]->erase(node))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1257,7 +1257,7 @@ private:
|
|||||||
void set_value (SGPropertyNode * value);
|
void set_value (SGPropertyNode * value);
|
||||||
private:
|
private:
|
||||||
string _key;
|
string _key;
|
||||||
SGSharedPtr<SGPropertyNode> _value;
|
SGSharedPtr<SGPropertyNode> _value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user