diff options
author | Michele Calgaro <[email protected]> | 2014-08-02 21:23:15 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2014-08-02 21:23:15 +0900 |
commit | 6fb1d18ed13beaee8c8e48a25ff0c4a075d872b5 (patch) | |
tree | d855a538d1d13e4828b189b34373aaa83f5dc9f4 | |
parent | 0c50fad6c7792e3b1c3e1a019c99905c52927baf (diff) | |
download | tqt3-6fb1d18ed13beaee8c8e48a25ff0c4a075d872b5.tar.gz tqt3-6fb1d18ed13beaee8c8e48a25ff0c4a075d872b5.zip |
Improvements to TQValueList. This may relate to bug 1820
-rw-r--r-- | src/tools/ntqvaluelist.h | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/tools/ntqvaluelist.h b/src/tools/ntqvaluelist.h index 9ee9ee5e5..b9fc73098 100644 --- a/src/tools/ntqvaluelist.h +++ b/src/tools/ntqvaluelist.h @@ -229,12 +229,6 @@ public: TQValueListPrivate(); TQValueListPrivate( const TQValueListPrivate<T>& _p ); - void derefAndDelete() // ### hack to get around hp-cc brain damage - { - if ( deref() ) - delete this; - } - #if defined(Q_TEMPLATEDLL) // Workaround MS bug in memory de/allocation in DLL vs. EXE virtual @@ -258,14 +252,14 @@ public: template <class T> Q_INLINE_TEMPLATES TQValueListPrivate<T>::TQValueListPrivate() { - node = new Node; node->next = node->prev = node; nodes = 0; + node = new Node(); node->next = node->prev = node; nodes = 0; } template <class T> Q_INLINE_TEMPLATES TQValueListPrivate<T>::TQValueListPrivate( const TQValueListPrivate<T>& _p ) : TQShared() { - node = new Node; node->next = node->prev = node; nodes = 0; + node = new Node(); node->next = node->prev = node; nodes = 0; Iterator b( _p.node->next ); Iterator e( _p.node ); Iterator i( node ); @@ -452,15 +446,23 @@ public: tqCopy( l.begin(), l.end(), std::back_inserter( *this ) ); } #endif - ~TQValueList() { sh->derefAndDelete(); } + ~TQValueList() + { + if (sh->deref()) + delete sh; + } TQValueList<T>& operator= ( const TQValueList<T>& l ) { + if (this == &l || sh == l.sh) + return *this; // Do nothing is self-assigning l.sh->ref(); - sh->derefAndDelete(); + if (sh->deref()) + delete sh; sh = l.sh; return *this; } + #ifndef QT_NO_STL TQValueList<T>& operator= ( const std::list<T>& l ) { @@ -468,6 +470,7 @@ public: tqCopy( l.begin(), l.end(), std::back_inserter( *this ) ); return *this; } + bool operator== ( const std::list<T>& l ) const { if ( size() != l.size() ) @@ -574,7 +577,14 @@ protected: /** * Helpers */ - void detach() { if ( sh->count > 1 ) detachInternal(); } + void detach() + { + if (sh->count > 1) + { + sh->deref(); + sh = new TQValueListPrivate<T>(*sh); + } + } /** * Variables @@ -582,8 +592,6 @@ protected: TQValueListPrivate<T>* sh; private: - void detachInternal(); - friend class TQDeepCopy< TQValueList<T> >; }; @@ -603,7 +611,7 @@ Q_INLINE_TEMPLATES bool TQValueList<T>::operator== ( const TQValueList<T>& l ) c template <class T> Q_INLINE_TEMPLATES void TQValueList<T>::clear() { - if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new TQValueListPrivate<T>; } + if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new TQValueListPrivate<T>(); } } template <class T> @@ -640,12 +648,6 @@ Q_INLINE_TEMPLATES TQValueList<T>& TQValueList<T>::operator+= ( const TQValueLis return *this; } -template <class T> -Q_INLINE_TEMPLATES void TQValueList<T>::detachInternal() -{ - sh->deref(); sh = new TQValueListPrivate<T>( *sh ); -} - #ifndef QT_NO_DATASTREAM template <class T> Q_INLINE_TEMPLATES TQDataStream& operator>>( TQDataStream& s, TQValueList<T>& l ) |