From 6fb1d18ed13beaee8c8e48a25ff0c4a075d872b5 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 2 Aug 2014 21:23:15 +0900 Subject: Improvements to TQValueList. This may relate to bug 1820 --- src/tools/ntqvaluelist.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/tools/ntqvaluelist.h') 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& _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 Q_INLINE_TEMPLATES TQValueListPrivate::TQValueListPrivate() { - node = new Node; node->next = node->prev = node; nodes = 0; + node = new Node(); node->next = node->prev = node; nodes = 0; } template Q_INLINE_TEMPLATES TQValueListPrivate::TQValueListPrivate( const TQValueListPrivate& _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& operator= ( const TQValueList& 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& operator= ( const std::list& l ) { @@ -468,6 +470,7 @@ public: tqCopy( l.begin(), l.end(), std::back_inserter( *this ) ); return *this; } + bool operator== ( const std::list& 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(*sh); + } + } /** * Variables @@ -582,8 +592,6 @@ protected: TQValueListPrivate* sh; private: - void detachInternal(); - friend class TQDeepCopy< TQValueList >; }; @@ -603,7 +611,7 @@ Q_INLINE_TEMPLATES bool TQValueList::operator== ( const TQValueList& l ) c template Q_INLINE_TEMPLATES void TQValueList::clear() { - if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new TQValueListPrivate; } + if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new TQValueListPrivate(); } } template @@ -640,12 +648,6 @@ Q_INLINE_TEMPLATES TQValueList& TQValueList::operator+= ( const TQValueLis return *this; } -template -Q_INLINE_TEMPLATES void TQValueList::detachInternal() -{ - sh->deref(); sh = new TQValueListPrivate( *sh ); -} - #ifndef QT_NO_DATASTREAM template Q_INLINE_TEMPLATES TQDataStream& operator>>( TQDataStream& s, TQValueList& l ) -- cgit v1.2.1