Signed-off-by: Gabriel Ivăncescu gabrielopcode@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; + } + } +} + static BOOL is_item_selected(LB_DESCR *descr, UINT index) { return descr->items[index].selected; @@ -1661,7 +1679,6 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index ) static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index ) { LB_ITEMDATA *item; - INT max_items;
if ((index < 0) || (index >= descr->nb_items)) return LB_ERR;
@@ -1681,20 +1698,8 @@ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index ) (descr->nb_items - index) * sizeof(LB_ITEMDATA) ); if (descr->anchor_item == descr->nb_items) descr->anchor_item--;
- /* Shrink the item array if possible */ + shrink_storage(descr);
- max_items = descr->array_size; - if (descr->nb_items < max_items - 2*LB_ARRAY_GRANULARITY) - { - max_items -= LB_ARRAY_GRANULARITY; - item = HeapReAlloc( GetProcessHeap(), 0, descr->items, - max_items * sizeof(LB_ITEMDATA) ); - if (item) - { - descr->array_size = max_items; - descr->items = item; - } - } /* Repaint the items */
LISTBOX_UpdateScroll( descr );