From 79ebd4147ed27ac75e6403efa7825242b06d6bda Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 6 Dec 2024 14:48:50 -0500 Subject: [PATCH] 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 --- headers/os/support/List.h | 2 +- src/kits/support/List.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/headers/os/support/List.h b/headers/os/support/List.h index dd38992b1f..8d985c151a 100644 --- a/headers/os/support/List.h +++ b/headers/os/support/List.h @@ -11,7 +11,7 @@ class BList { public: - BList(int32 count = 20); + BList(int32 blockSize = 20); BList(const BList& other); virtual ~BList(); diff --git a/src/kits/support/List.cpp b/src/kits/support/List.cpp index a9788d1c69..10f339b45f 100644 --- a/src/kits/support/List.cpp +++ b/src/kits/support/List.cpp @@ -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; }