mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Improved removal performance in Maxsi::SortedList.
This commit is contained in:
parent
f29f6dd053
commit
ac51e98cb8
1 changed files with 10 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
|
@ -149,20 +149,19 @@ namespace Maxsi
|
|||
if ( !(flags & FLAG_SORTED) ) { Sort(); }
|
||||
ASSERT(index < listused);
|
||||
|
||||
T result = list[index];
|
||||
// TODO: It may be possible to further speed up removal by delaying
|
||||
// the expensive memory copy operation.
|
||||
|
||||
if ( index == listused-1 )
|
||||
T result = list[index];
|
||||
list[index].~T();
|
||||
for ( size_t i = index+1; i < listused; i++ )
|
||||
{
|
||||
list[--listused].~T();
|
||||
}
|
||||
else
|
||||
{
|
||||
list[index].~T();
|
||||
list[index] = list[--listused];
|
||||
list[listused].~T();
|
||||
flags &= ~FLAG_SORTED;
|
||||
list[i-1] = list[i];
|
||||
list[i].~T();
|
||||
}
|
||||
|
||||
listused--;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue