diff --git a/src/location_vector.cpp b/src/location_vector.cpp index 5db7fd1ee838..70704e7aded6 100644 --- a/src/location_vector.cpp +++ b/src/location_vector.cpp @@ -44,18 +44,13 @@ location_vector::iterator::iterator() = default; template location_vector::iterator::iterator( typename std::vector::iterator it, const location_vector &home ) : it( it ), home( &home ) -{ - this->home->locked++; -}; +{}; template location_vector::iterator::iterator( const location_vector::iterator &source ) { this->it = source.it; this->home = source.home; - if( this->home ) { - this->home->locked++; - } }; template @@ -72,12 +67,8 @@ template typename location_vector::iterator &location_vector::iterator::operator=( const location_vector::iterator &source ) { - release_locked(); this->it = source.it; this->home = source.home; - if( this->home ) { - this->home->locked++; - } return *this; }; @@ -86,7 +77,6 @@ typename location_vector::iterator &location_vector::iterator::operator= ( location_vector::iterator &&source ) noexcept { - release_locked(); this->it = source.it; this->home = source.home; source.home = nullptr; @@ -94,33 +84,12 @@ noexcept return *this; }; -template -location_vector::iterator::~iterator() -{ - release_locked(); -}; - - -template -void location_vector::iterator::release_locked() -{ - - if( this->home ) { - this->home->locked--; - if( this->home->locked < 0 ) { - debugmsg( "Location vector's locked is negative" ); - } - } -} template location_vector::const_iterator::const_iterator( const iterator &source ) { this->it = source.it; this->home = source.home; - if( this->home ) { - this->home->locked++; - } } template @@ -138,9 +107,7 @@ location_vector::const_iterator::const_iterator() = default; template location_vector::const_iterator::const_iterator( typename std::vector::const_iterator it, const location_vector &home ) : it( it ), home( &home ) -{ - this->home->locked++; -}; +{}; template location_vector::const_iterator::const_iterator( const location_vector::const_iterator @@ -148,9 +115,6 @@ location_vector::const_iterator::const_iterator( const location_vector::co { this->it = source.it; this->home = source.home; - if( this->home ) { - this->home->locked++; - } }; template @@ -167,12 +131,8 @@ template typename location_vector::const_iterator &location_vector::const_iterator::operator= ( const location_vector::const_iterator &source ) { - release_locked(); this->it = source.it; this->home = source.home; - if( this->home ) { - this->home->locked++; - } return *this; }; @@ -181,7 +141,6 @@ typename location_vector::const_iterator &location_vector::const_iterator: ( location_vector::const_iterator &&source ) noexcept { - release_locked(); this->it = source.it; this->home = source.home; source.home = nullptr; @@ -189,33 +148,12 @@ noexcept return *this; }; -template -location_vector::const_iterator::~const_iterator() -{ - release_locked(); -}; - - -template -void location_vector::const_iterator::release_locked() -{ - - if( this->home ) { - this->home->locked--; - if( this->home->locked < 0 ) { - debugmsg( "Location vector's locked is negative" ); - } - } -} template void location_vector::push_back( detached_ptr &&obj ) { - if( locked > 0 ) { - debugmsg( "Attempting to push_back to a vector with active iterators" ); - } if( !obj ) { return; } @@ -260,9 +198,6 @@ T *location_vector::back() const template detached_ptr location_vector::remove( T *obj ) { - if( locked > 0 ) { - debugmsg( "Attempting to remove something from a vector with active iterators" ); - } if( destroyed ) { debugmsg( "Attempted to remove something from a destroyed location." ); return detached_ptr(); @@ -290,9 +225,6 @@ typename location_vector::iterator location_vector::erase( typename location_vector::const_iterator it, detached_ptr *out ) { - if( locked > 2 ) { - debugmsg( "Attempting to erase something from a vector with more than 1 active iterator" ); - } if( destroyed && out ) { debugmsg( "Attempted to erase something from a destroyed location." ); return location_vector::iterator( contents.end(), *this ); @@ -313,9 +245,6 @@ typename location_vector::iterator location_vector::insert( typename location_vector::iterator it, detached_ptr &&obj ) { - if( locked > 2 ) { - debugmsg( "Attempting to insert something into a vector with more than 1 active iterator" ); - } if( !obj ) { return it; } @@ -341,9 +270,6 @@ typename location_vector::iterator location_vector::insert( typename typename std::vector>::iterator start, typename std::vector>::iterator end ) { - if( locked > 2 ) { - debugmsg( "Attempting to insert something into a vector with more than 1 active iterator" ); - } for( auto iter = start; iter != end; iter++ ) { if( !*iter ) { continue; @@ -462,9 +388,6 @@ location *location_vector::get_location() const template typename std::vector> location_vector::clear() { - if( locked > 0 ) { - debugmsg( "Attempting to clear a vector with active iterators" ); - } if( destroyed ) { debugmsg( "Attempted to clear a destroyed location." ); return std::vector>(); @@ -481,14 +404,10 @@ typename std::vector> location_vector::clear() template void location_vector::remove_with( std::function < detached_ptr( detached_ptr && ) > cb ) { - if( locked > 0 ) { - debugmsg( "Attempting to remove_with a vector with active iterators" ); - } if( destroyed ) { debugmsg( "Attempted to remove_with from a destroyed location." ); return; } - locked++; for( auto it = contents.begin(); it != contents.end(); ) { location *saved_loc = ( *it )->loc; ( *it )->remove_location(); @@ -506,7 +425,6 @@ void location_vector::remove_with( std::function < detached_ptr( detached_ it = contents.erase( it ); } } - locked--; } template diff --git a/src/location_vector.h b/src/location_vector.h index ad4ba2451034..9b2ef57313fb 100644 --- a/src/location_vector.h +++ b/src/location_vector.h @@ -31,7 +31,6 @@ class location_vector private: std::unique_ptr> loc; std::vector contents; - mutable int locked = 0; bool destroyed = false; template @@ -55,7 +54,6 @@ class location_vector iterator( iterator &&source ) noexcept ; iterator &operator=( const iterator &source ); iterator &operator=( iterator &&source ) noexcept ; - ~iterator(); reference operator*() const { return *it; @@ -127,7 +125,6 @@ class location_vector }; private: - void release_locked(); typename std::vector::iterator it; const location_vector *home = nullptr; }; @@ -150,7 +147,6 @@ class location_vector const_iterator( const_iterator &&source ) noexcept ; const_iterator &operator=( const const_iterator &source ); const_iterator &operator=( const_iterator &&source ) noexcept ; - ~const_iterator(); reference operator*() const { return *it; @@ -224,7 +220,6 @@ class location_vector private: typename std::vector::const_iterator it; const location_vector *home; - void release_locked(); }; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator;