BList: Slight code and parameter name cleanup.

* Clarify the fResizeThreshold logic and remove the comment.

 * Rename "count" constructor argument to "blockSize", as this is
   what it actually does.

No functional change intended.

Change-Id: I993bf0e695f47da181e9fb50b9a964edfd4a0adc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8629
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2024-12-06 19:52:05 +00:00
committed by waddlesplash
parent ddd374f0fe
commit 79ebd4147e
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
class BList {
public:
BList(int32 count = 20);
BList(int32 blockSize = 20);
BList(const BList& other);
virtual ~BList();
+7 -7
View File
@@ -29,12 +29,12 @@ move_items(void** items, int32 offset, int32 count)
}
BList::BList(int32 count)
BList::BList(int32 blockSize)
:
fObjectList(NULL),
fPhysicalSize(0),
fItemCount(0),
fBlockSize(count),
fBlockSize(blockSize),
fResizeThreshold(0)
{
if (fBlockSize <= 0)
@@ -474,7 +474,6 @@ void BList::_ReservedList2() {}
bool
BList::_ResizeArray(int32 count)
{
bool result = true;
// calculate the new physical size
// by doubling the existing size
// until we can hold at least count items
@@ -490,16 +489,17 @@ BList::_ResizeArray(int32 count)
newSize = fResizeThreshold;
// resize if necessary
bool result = true;
if (newSize != fPhysicalSize) {
void** newObjectList
= (void**)realloc(fObjectList, newSize * sizeof(void*));
if (newObjectList) {
fObjectList = newObjectList;
fPhysicalSize = newSize;
// set our lower bound to either 1/4
//of the current physical size, or 0
fResizeThreshold = fPhysicalSize >> 2 >= fBlockSize
? fPhysicalSize >> 2 : 0;
fResizeThreshold = (fPhysicalSize / 4);
if (fResizeThreshold < fBlockSize)
fResizeThreshold = 0;
} else
result = false;
}