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:
committed by
waddlesplash
parent
ddd374f0fe
commit
79ebd4147e
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
class BList {
|
class BList {
|
||||||
public:
|
public:
|
||||||
BList(int32 count = 20);
|
BList(int32 blockSize = 20);
|
||||||
BList(const BList& other);
|
BList(const BList& other);
|
||||||
virtual ~BList();
|
virtual ~BList();
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ move_items(void** items, int32 offset, int32 count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BList::BList(int32 count)
|
BList::BList(int32 blockSize)
|
||||||
:
|
:
|
||||||
fObjectList(NULL),
|
fObjectList(NULL),
|
||||||
fPhysicalSize(0),
|
fPhysicalSize(0),
|
||||||
fItemCount(0),
|
fItemCount(0),
|
||||||
fBlockSize(count),
|
fBlockSize(blockSize),
|
||||||
fResizeThreshold(0)
|
fResizeThreshold(0)
|
||||||
{
|
{
|
||||||
if (fBlockSize <= 0)
|
if (fBlockSize <= 0)
|
||||||
@@ -474,7 +474,6 @@ void BList::_ReservedList2() {}
|
|||||||
bool
|
bool
|
||||||
BList::_ResizeArray(int32 count)
|
BList::_ResizeArray(int32 count)
|
||||||
{
|
{
|
||||||
bool result = true;
|
|
||||||
// calculate the new physical size
|
// calculate the new physical size
|
||||||
// by doubling the existing size
|
// by doubling the existing size
|
||||||
// until we can hold at least count items
|
// until we can hold at least count items
|
||||||
@@ -490,16 +489,17 @@ BList::_ResizeArray(int32 count)
|
|||||||
newSize = fResizeThreshold;
|
newSize = fResizeThreshold;
|
||||||
|
|
||||||
// resize if necessary
|
// resize if necessary
|
||||||
|
bool result = true;
|
||||||
if (newSize != fPhysicalSize) {
|
if (newSize != fPhysicalSize) {
|
||||||
void** newObjectList
|
void** newObjectList
|
||||||
= (void**)realloc(fObjectList, newSize * sizeof(void*));
|
= (void**)realloc(fObjectList, newSize * sizeof(void*));
|
||||||
if (newObjectList) {
|
if (newObjectList) {
|
||||||
fObjectList = newObjectList;
|
fObjectList = newObjectList;
|
||||||
fPhysicalSize = newSize;
|
fPhysicalSize = newSize;
|
||||||
// set our lower bound to either 1/4
|
|
||||||
//of the current physical size, or 0
|
fResizeThreshold = (fPhysicalSize / 4);
|
||||||
fResizeThreshold = fPhysicalSize >> 2 >= fBlockSize
|
if (fResizeThreshold < fBlockSize)
|
||||||
? fPhysicalSize >> 2 : 0;
|
fResizeThreshold = 0;
|
||||||
} else
|
} else
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user