[PATCH v5 8/8] comctl32/listbox: Shrink the item array in a helper function
Alexandre Julliard
julliard at winehq.org
Thu Nov 22 08:10:21 CST 2018
Huw Davies <huw at codeweavers.com> writes:
> On Thu, Nov 22, 2018 at 03:44:44PM +0200, Gabriel Ivăncescu wrote:
>> Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
>> ---
>> dlls/comctl32/listbox.c | 33 +++++++++++++++++++--------------
>> 1 file changed, 19 insertions(+), 14 deletions(-)
>>
>> diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
>> index 3b76e19..41eb631 100644
>> --- a/dlls/comctl32/listbox.c
>> +++ b/dlls/comctl32/listbox.c
>> @@ -148,6 +148,24 @@ static BOOL expand_storage(LB_DESCR *descr, UINT amount)
>> return TRUE;
>> }
>>
>> +static void shrink_storage(LB_DESCR *descr)
>> +{
>> + LB_ITEMDATA *p = descr->items;
>> + UINT num = descr->nb_items;
>> +
>> + if (num + LB_ARRAY_GRANULARITY * 2 < descr->array_size)
>> + {
>> + num += LB_ARRAY_GRANULARITY - 1;
>> + num -= num % LB_ARRAY_GRANULARITY;
>> + p = HeapReAlloc(GetProcessHeap(), 0, p, num * sizeof(LB_ITEMDATA));
>> + if (p)
>> + {
>> + descr->array_size = num;
>> + descr->items = p;
>> + }
>> + }
>> +}
>> +
>
> I was hoping for a common allocation function (resize_storage() say),
> that would take the length of the required array, not one function to
> grow and another to shrink.
>
> Also, let's insist that LB_ARRAY_GRANULARITY is a power of two, to
> simplify these adjustments.
Note that doubling the size when growing would be better than a fixed
constant (but maybe we want to avoid changing even more things at this
point...)
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list