Only increase the item array if we actually have to. Previously, sending for example just 1 to nb_items repeatedly would always increase the array by LB_ARRAY_GRANULARITY, even if there was plenty of space available.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index afa6700..f7ed2b8 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -36,6 +36,7 @@ #include "wine/unicode.h" #include "wine/exception.h" #include "wine/debug.h" +#include "wine/heap.h"
#include "comctl32.h"
@@ -675,22 +676,19 @@ static void LISTBOX_DrawFocusRect( LB_DESCR *descr, BOOL on ) /*********************************************************************** * LISTBOX_InitStorage */ -static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items ) +static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, UINT nb_items ) { LB_ITEMDATA *item;
- nb_items += LB_ARRAY_GRANULARITY - 1; - nb_items -= (nb_items % LB_ARRAY_GRANULARITY); if (descr->items) { - nb_items += descr->array_size; - item = HeapReAlloc( GetProcessHeap(), 0, descr->items, - nb_items * sizeof(LB_ITEMDATA)); - } - else { - item = HeapAlloc( GetProcessHeap(), 0, - nb_items * sizeof(LB_ITEMDATA)); + nb_items += descr->nb_items; + if (nb_items <= descr->array_size) return LB_OKAY; }
+ nb_items += LB_ARRAY_GRANULARITY - 1; + nb_items -= nb_items % LB_ARRAY_GRANULARITY; + item = heap_realloc(descr->items, nb_items * sizeof(*item)); + if (!item) { SEND_NOTIFICATION( descr, LBN_ERRSPACE );