Rework BList's Resize() functionality: instead of altering the size of the list a block at a time,
we now double/halve the current size of the list, starting with the constructor blocksize as a baseline. This has the net effect that when doing large numbers of inserts/removes, the number of resize operations needed scales logarithmically to the number of operations, which should yield a decent performance improvement in such cases. Review welcome. This does not yet affect ticket #2363 that I'm aware of, as I'm currently in the process of attempting to find a copy of said app to test with. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25916 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
97403a77f1
commit
864ace1845
@ -174,7 +174,7 @@ BList::RemoveItem(int32 index)
|
|||||||
if (index >= 0 && index < fItemCount) {
|
if (index >= 0 && index < fItemCount) {
|
||||||
item = fObjectList[index];
|
item = fObjectList[index];
|
||||||
move_items(fObjectList + index + 1, -1, fItemCount - index - 1);
|
move_items(fObjectList + index + 1, -1, fItemCount - index - 1);
|
||||||
Resize(fItemCount - 1);
|
Resize(fItemCount - 1);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -433,11 +433,17 @@ bool
|
|||||||
BList::Resize(int32 count)
|
BList::Resize(int32 count)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
// calculate the new physical size
|
// calculate the new physical size
|
||||||
int32 newSize = count;
|
// by doubling the existing size
|
||||||
if (newSize <= 0)
|
// until we can hold at least count items
|
||||||
newSize = 1;
|
int32 newSize = fBlockSize;
|
||||||
newSize = ((newSize - 1) / fBlockSize + 1) * fBlockSize;
|
if (count <= 0)
|
||||||
|
count = fBlockSize;
|
||||||
|
if ((size_t)count != fPhysicalSize)
|
||||||
|
while (newSize < count)
|
||||||
|
newSize <<= 1;
|
||||||
|
|
||||||
// resize if necessary
|
// resize if necessary
|
||||||
if ((size_t)newSize != fPhysicalSize) {
|
if ((size_t)newSize != fPhysicalSize) {
|
||||||
void** newObjectList
|
void** newObjectList
|
||||||
|
Loading…
x
Reference in New Issue
Block a user