[PATCH v4 07/11] comctl32/listbox: Add a new field to store the items array size instead of using HeapSize
Gabriel Ivăncescu
gabrielopcode at gmail.com
Wed Nov 21 13:15:10 CST 2018
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
dlls/comctl32/listbox.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index e05ab6f..afa6700 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -70,6 +70,7 @@ typedef struct
UINT style; /* Window style */
INT width; /* Window width */
INT height; /* Window height */
+ UINT array_size; /* Total number of allocated items in the array */
LB_ITEMDATA *items; /* Array of items */
INT nb_items; /* Number of items */
INT top_item; /* Top visible item */
@@ -681,7 +682,7 @@ static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items )
nb_items += LB_ARRAY_GRANULARITY - 1;
nb_items -= (nb_items % LB_ARRAY_GRANULARITY);
if (descr->items) {
- nb_items += HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item);
+ nb_items += descr->array_size;
item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
nb_items * sizeof(LB_ITEMDATA));
}
@@ -695,6 +696,7 @@ static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items )
SEND_NOTIFICATION( descr, LBN_ERRSPACE );
return LB_ERRSPACE;
}
+ descr->array_size = nb_items;
descr->items = item;
return LB_OKAY;
}
@@ -1516,14 +1518,11 @@ static LRESULT LISTBOX_InsertItem( LB_DESCR *descr, INT index,
LPWSTR str, ULONG_PTR data )
{
LB_ITEMDATA *item;
- INT max_items;
INT oldfocus = descr->focus_item;
if (index == -1) index = descr->nb_items;
else if ((index < 0) || (index > descr->nb_items)) return LB_ERR;
- if (!descr->items) max_items = 0;
- else max_items = HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(*item);
- if (descr->nb_items == max_items)
+ if (descr->nb_items == descr->array_size)
{
/* We need to grow the array */
if (LISTBOX_InitStorage(descr, 1) == LB_ERRSPACE)
@@ -1686,13 +1685,17 @@ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index )
/* Shrink the item array if possible */
- max_items = HeapSize( GetProcessHeap(), 0, descr->items ) / sizeof(LB_ITEMDATA);
+ 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->items = item;
+ if (item)
+ {
+ descr->array_size = max_items;
+ descr->items = item;
+ }
}
/* Repaint the items */
@@ -1738,6 +1741,7 @@ static void LISTBOX_ResetContent( LB_DESCR *descr )
descr->selected_item = -1;
descr->focus_item = 0;
descr->anchor_item = -1;
+ descr->array_size = 0;
descr->items = NULL;
}
@@ -2475,6 +2479,7 @@ static BOOL LISTBOX_Create( HWND hwnd, LPHEADCOMBO lphc )
descr->width = rect.right - rect.left;
descr->height = rect.bottom - rect.top;
descr->items = NULL;
+ descr->array_size = 0;
descr->nb_items = 0;
descr->top_item = 0;
descr->selected_item = -1;
--
2.19.1
More information about the wine-devel
mailing list