diff options
author | Bertrand Augereau | 2008-03-30 06:37:46 +0000 |
---|---|---|
committer | Bertrand Augereau | 2008-03-30 06:37:46 +0000 |
commit | 78419238f909dc2af0bb5740c71052f7a570fa49 (patch) | |
tree | b888e05400a023ddbe58bf9f141b473992fb6f7e /common | |
parent | 49e3efe55eb26ad3e499a8cc44c5de11e011d361 (diff) | |
download | scummvm-rg350-78419238f909dc2af0bb5740c71052f7a570fa49.tar.gz scummvm-rg350-78419238f909dc2af0bb5740c71052f7a570fa49.tar.bz2 scummvm-rg350-78419238f909dc2af0bb5740c71052f7a570fa49.zip |
The "anchor" (root) of the linked list is now constructed inplace in the List instead of being newed (it has the same lifetime as the List itself anyway)
svn-id: r31323
Diffstat (limited to 'common')
-rw-r--r-- | common/list.h | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/common/list.h b/common/list.h index 08b964eddf..5629c40a0d 100644 --- a/common/list.h +++ b/common/list.h @@ -111,7 +111,7 @@ public: } }; - NodeBase *_anchor; + NodeBase _anchor; public: typedef Iterator<t_T> iterator; @@ -121,21 +121,18 @@ public: public: List() { - _anchor = new NodeBase; - _anchor->_prev = _anchor; - _anchor->_next = _anchor; + _anchor._prev = &_anchor; + _anchor._next = &_anchor; } List(const List<t_T>& list) { - _anchor = new NodeBase; - _anchor->_prev = _anchor; - _anchor->_next = _anchor; + _anchor._prev = &_anchor; + _anchor._next = &_anchor; insert(begin(), list.begin(), list.end()); } ~List() { clear(); - delete _anchor; } void push_front(const t_T& element) { @@ -232,32 +229,32 @@ public: } bool empty() const { - return (_anchor == _anchor->_next); + return (&_anchor == _anchor._next); } iterator begin() { - return iterator(_anchor->_next); + return iterator(_anchor._next); } iterator reverse_begin() { - return iterator(_anchor->_prev); + return iterator(_anchor._prev); } iterator end() { - return iterator(_anchor); + return iterator(&_anchor); } const_iterator begin() const { - return const_iterator(_anchor->_next); + return const_iterator(_anchor._next); } const_iterator reverse_begin() const { - return const_iterator(_anchor->_prev); + return const_iterator(_anchor._prev); } const_iterator end() const { - return const_iterator(_anchor); + return const_iterator(const_cast<NodeBase*>(&_anchor)); } }; |