From dfdffe1ac6f9b5e0e9577b9bc6dcaacef8ac9401 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 6 Dec 2024 14:50:37 -0500 Subject: [PATCH] BList: Allocate lazily. Rather than allocating a block in the constructor, just wait to do it until we actually need to add items to the list. This saves over 200,000 allocations when running "pkgman search" alone. Change-Id: Ia6a21b963efded2bb4973edc2ba22ff026e01737 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8630 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- src/kits/support/List.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kits/support/List.cpp b/src/kits/support/List.cpp index 10f339b45f..98e785d955 100644 --- a/src/kits/support/List.cpp +++ b/src/kits/support/List.cpp @@ -39,7 +39,6 @@ BList::BList(int32 blockSize) { if (fBlockSize <= 0) fBlockSize = 1; - _ResizeArray(fItemCount); } @@ -474,6 +473,9 @@ void BList::_ReservedList2() {} bool BList::_ResizeArray(int32 count) { + if (fPhysicalSize == count) + return true; + // calculate the new physical size // by doubling the existing size // until we can hold at least count items