Skip to content

Commit

Permalink
fix: Remove active iterator messages (#3801)
Browse files Browse the repository at this point in the history
Remove active iterator messages
  • Loading branch information
joveeater authored Dec 2, 2023
1 parent 6ffdc50 commit 22b52f8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 89 deletions.
86 changes: 2 additions & 84 deletions src/location_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,13 @@ location_vector<T>::iterator::iterator() = default;
template<typename T>
location_vector<T>::iterator::iterator( typename std::vector<T *>::iterator it,
const location_vector<T> &home ) : it( it ), home( &home )
{
this->home->locked++;
};
{};

template<typename T>
location_vector<T>::iterator::iterator( const location_vector<T>::iterator &source )
{
this->it = source.it;
this->home = source.home;
if( this->home ) {
this->home->locked++;
}
};

template<typename T>
Expand All @@ -72,12 +67,8 @@ template<typename T>
typename location_vector<T>::iterator &location_vector<T>::iterator::operator=( const
location_vector<T>::iterator &source )
{
release_locked();
this->it = source.it;
this->home = source.home;
if( this->home ) {
this->home->locked++;
}
return *this;
};

Expand All @@ -86,41 +77,19 @@ typename location_vector<T>::iterator &location_vector<T>::iterator::operator=
( location_vector<T>::iterator &&source )
noexcept
{
release_locked();
this->it = source.it;
this->home = source.home;
source.home = nullptr;
source.it = {};
return *this;
};

template<typename T>
location_vector<T>::iterator::~iterator()
{
release_locked();
};


template<typename T>
void location_vector<T>::iterator::release_locked()
{

if( this->home ) {
this->home->locked--;
if( this->home->locked < 0 ) {
debugmsg( "Location vector's locked is negative" );
}
}
}

template<typename T>
location_vector<T>::const_iterator::const_iterator( const iterator &source )
{
this->it = source.it;
this->home = source.home;
if( this->home ) {
this->home->locked++;
}
}

template<typename T>
Expand All @@ -138,19 +107,14 @@ location_vector<T>::const_iterator::const_iterator() = default;
template<typename T>
location_vector<T>::const_iterator::const_iterator( typename std::vector<T *>::const_iterator it,
const location_vector<T> &home ) : it( it ), home( &home )
{
this->home->locked++;
};
{};

template<typename T>
location_vector<T>::const_iterator::const_iterator( const location_vector<T>::const_iterator
&source )
{
this->it = source.it;
this->home = source.home;
if( this->home ) {
this->home->locked++;
}
};

template<typename T>
Expand All @@ -167,12 +131,8 @@ template<typename T>
typename location_vector<T>::const_iterator &location_vector<T>::const_iterator::operator=
( const location_vector<T>::const_iterator &source )
{
release_locked();
this->it = source.it;
this->home = source.home;
if( this->home ) {
this->home->locked++;
}
return *this;
};

Expand All @@ -181,41 +141,19 @@ typename location_vector<T>::const_iterator &location_vector<T>::const_iterator:
( location_vector<T>::const_iterator &&source )
noexcept
{
release_locked();
this->it = source.it;
this->home = source.home;
source.home = nullptr;
source.it = {};
return *this;
};

template<typename T>
location_vector<T>::const_iterator::~const_iterator()
{
release_locked();
};


template<typename T>
void location_vector<T>::const_iterator::release_locked()
{

if( this->home ) {
this->home->locked--;
if( this->home->locked < 0 ) {
debugmsg( "Location vector's locked is negative" );
}
}
}



template<typename T>
void location_vector<T>::push_back( detached_ptr<T> &&obj )
{
if( locked > 0 ) {
debugmsg( "Attempting to push_back to a vector with active iterators" );
}
if( !obj ) {
return;
}
Expand Down Expand Up @@ -260,9 +198,6 @@ T *location_vector<T>::back() const
template<typename T>
detached_ptr<T> location_vector<T>::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<T>();
Expand Down Expand Up @@ -290,9 +225,6 @@ typename location_vector<T>::iterator location_vector<T>::erase( typename
location_vector<T>::const_iterator it,
detached_ptr<T> *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<T>::iterator( contents.end(), *this );
Expand All @@ -313,9 +245,6 @@ typename location_vector<T>::iterator location_vector<T>::insert( typename
location_vector<T>::iterator it,
detached_ptr<T> &&obj )
{
if( locked > 2 ) {
debugmsg( "Attempting to insert something into a vector with more than 1 active iterator" );
}
if( !obj ) {
return it;
}
Expand All @@ -341,9 +270,6 @@ typename location_vector<T>::iterator location_vector<T>::insert( typename
typename std::vector<detached_ptr<T>>::iterator start,
typename std::vector<detached_ptr<T>>::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;
Expand Down Expand Up @@ -462,9 +388,6 @@ location<T> *location_vector<T>::get_location() const
template<typename T>
typename std::vector<detached_ptr<T>> location_vector<T>::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<detached_ptr<T>>();
Expand All @@ -481,14 +404,10 @@ typename std::vector<detached_ptr<T>> location_vector<T>::clear()
template<typename T>
void location_vector<T>::remove_with( std::function < detached_ptr<T>( detached_ptr<T> && ) > 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<T> *saved_loc = ( *it )->loc;
( *it )->remove_location();
Expand All @@ -506,7 +425,6 @@ void location_vector<T>::remove_with( std::function < detached_ptr<T>( detached_
it = contents.erase( it );
}
}
locked--;
}

template<typename T>
Expand Down
5 changes: 0 additions & 5 deletions src/location_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class location_vector
private:
std::unique_ptr<location<T>> loc;
std::vector<T *> contents;
mutable int locked = 0;
bool destroyed = false;

template<typename U>
Expand All @@ -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;
Expand Down Expand Up @@ -127,7 +125,6 @@ class location_vector
};

private:
void release_locked();
typename std::vector<T *>::iterator it;
const location_vector<T> *home = nullptr;
};
Expand All @@ -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;
Expand Down Expand Up @@ -224,7 +220,6 @@ class location_vector
private:
typename std::vector<T *>::const_iterator it;
const location_vector<T> *home;
void release_locked();
};
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
Expand Down

0 comments on commit 22b52f8

Please sign in to comment.