Use standard library for m_allItems defragmentation.

This commit is contained in:
Alex Shvartzkop 2024-07-01 21:37:23 +03:00
parent 787965c162
commit a4005193fb
1 changed files with 7 additions and 72 deletions

View File

@ -351,77 +351,6 @@ void VIEW::Add( VIEW_ITEM* aItem, int aDrawPriority )
}
static void DefragmentItems( std::vector<VIEW_ITEM*>& items )
{
size_t target = -1;
size_t sourceStart = -1;
size_t sourceEnd = -1;
for( size_t ia = 0; ia < items.size(); ia++ )
{
if( items[ia] == nullptr )
{
if( sourceStart != -1 && target != -1 && sourceEnd != -1 )
{
int len = sourceEnd - sourceStart + 1;
memmove( &items[target], &items[sourceStart], sizeof( items[0] ) * len );
target += len;
sourceStart = -1;
sourceEnd = -1;
}
if( target == -1 )
target = ia;
}
else
{
if( target != -1 )
{
if( sourceStart == -1 )
sourceStart = ia;
sourceEnd = ia;
}
}
}
if( sourceStart != -1 && target != -1 && sourceEnd != -1 )
{
int len = sourceEnd - sourceStart + 1;
memmove( &items[target], &items[sourceStart], sizeof( items[0] ) * len );
target += len;
sourceStart = -1;
sourceEnd = -1;
}
int needSize = 0;
if( target != -1 )
{
needSize = target;
}
else
{
for( int in = int( items.size() ) - 1; in >= 0; in-- )
{
if( items[in] != nullptr )
{
needSize = in + 1;
break;
}
}
}
items.resize( needSize );
}
void VIEW::Remove( VIEW_ITEM* aItem )
{
static int s_gcCounter = 0;
@ -440,7 +369,13 @@ void VIEW::Remove( VIEW_ITEM* aItem )
if( s_gcCounter > 4096 )
{
DefragmentItems( *m_allItems );
// Perform defragmentation
alg::delete_if( *m_allItems,
[]( VIEW_ITEM* it )
{
return it == nullptr;
} );
s_gcCounter = 0;
}
}