[PATCH v5 8/8] comctl32/listbox: Shrink the item array in a helper function

Gabriel Ivăncescu gabrielopcode at gmail.com
Thu Nov 22 09:28:37 CST 2018


On Thu, Nov 22, 2018 at 4:02 PM Huw Davies <huw at codeweavers.com> wrote:
>
> 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.
>
> Huw.

I didn't want to change too much in one patch. Also only growing
should give error when failing to allocate (as was the behavior
before). I think adding extra checks for that is going to make the
function uglier than it needs to be, since it will be effectively two
functions in one.



More information about the wine-devel mailing list