From 53d8cff8353c5733e7bba6317bf41144ac542500 Mon Sep 17 00:00:00 2001 From: mfranz Date: Sat, 17 Feb 2007 10:50:49 +0000 Subject: [PATCH] Csaba HALASZ: when a path_cache ceases to exist, unregister from all nodes that had been told that this node is linking to them mf: remove old erase-by-key methods; they are now unused and always were problematic, so they won't be used in the future either --- simgear/props/props.cxx | 47 ++++++++++++++--------------------------- simgear/props/props.hxx | 3 +-- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index 409ae0d4..786abf34 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -2227,24 +2227,6 @@ SGPropertyNode::hash_table::bucket::get_entry (const char * key, bool create) } } -void -SGPropertyNode::hash_table::bucket::erase (const char * key) -{ - int i; - for (i = 0; i < _length; i++) { - if (!strcmp(_entries[i]->get_key(), key)) - break; - } - - if (i < _length) { - delete _entries[i]; - for (++i; i < _length; i++) { - _entries[i-1] = _entries[i]; - } - _length--; - } -} - bool SGPropertyNode::hash_table::bucket::erase (SGPropertyNode * node) { @@ -2261,6 +2243,16 @@ SGPropertyNode::hash_table::bucket::erase (SGPropertyNode * node) return false; } +void +SGPropertyNode::hash_table::bucket::clear (SGPropertyNode::hash_table * owner) +{ + for (int i = 0; i < _length; i++) { + SGPropertyNode * node = _entries[i]->get_value(); + if (node) + node->remove_linked_node(owner); + } +} + SGPropertyNode::hash_table::hash_table () : _data_length(0), _data(0) @@ -2269,8 +2261,12 @@ SGPropertyNode::hash_table::hash_table () SGPropertyNode::hash_table::~hash_table () { - for (unsigned int i = 0; i < _data_length; i++) - delete _data[i]; + for (unsigned int i = 0; i < _data_length; i++) { + if (_data[i]) { + _data[i]->clear(this); + delete _data[i]; + } + } delete [] _data; } @@ -2307,17 +2303,6 @@ SGPropertyNode::hash_table::put (const char * key, SGPropertyNode * value) value->add_linked_node(this); } -void -SGPropertyNode::hash_table::erase (const char * key) -{ - if (_data_length == 0) - return; - unsigned int index = hashcode(key) % _data_length; - if (_data[index] == 0) - return; - _data[index]->erase(key); -} - bool SGPropertyNode::hash_table::erase (SGPropertyNode * node) { diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index a9dd24ef..12d7ba79 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -1269,8 +1269,8 @@ private: bucket (); ~bucket (); entry * get_entry (const char * key, bool create = false); - void erase (const char * key); bool erase (SGPropertyNode * node); + void clear (hash_table * owner); private: int _length; entry ** _entries; @@ -1282,7 +1282,6 @@ private: ~hash_table (); SGPropertyNode * get (const char * key); void put (const char * key, SGPropertyNode * value); - void erase (const char * key); bool erase (SGPropertyNode * node); private: -- 2.39.5