[PATCH] mieqProcessInputEvents - Lessen memory overhead

Peter Hutterer peter.hutterer at who-t.net
Sun Dec 14 15:37:20 PST 2008


On Sat, Dec 13, 2008 at 12:58:00AM -0800, Jeremy Huddleston wrote:
> This patch updates mieqProcessInputEvents to not xcalloc() for every  
> event it sees.
>
> diff --git a/mi/mieq.c b/mi/mieq.c
> index cb940e4..b865d82 100644
> --- a/mi/mieq.c
> +++ b/mi/mieq.c
> @@ -313,7 +313,8 @@ mieqProcessInputEvents(void)
>      int x = 0, y = 0;
>      int type, nevents, evlen, i;
>      ScreenPtr screen;
> -    xEvent *event;
> +    static xEvent *event = NULL;
> +    static size_t event_size = 0;
>      DeviceIntPtr dev = NULL,
>                   master = NULL;
>
> @@ -323,7 +324,10 @@ mieqProcessInputEvents(void)
>          /* GenericEvents always have nevents == 1 */
>          nevents = e->nevents;
>          evlen   = (nevents > 1) ? sizeof(xEvent) : e->events->evlen;
> -        event   = xcalloc(nevents, evlen);
> +        if((nevents * evlen) > event_size) {
> +            event_size = nevents * evlen;
> +            event = (xEvent *)xrealloc(event, event_size);
> +        }
>
>          if (!event)
>              FatalError("[mi] No memory left for event processing.\n");
> @@ -381,8 +385,6 @@ mieqProcessInputEvents(void)
>                      master->public.processInputProc(masterEvents- 
> >event, master,
>                                                      nevents);
>              }
> -
> -            xfree(event);
>          }
>
>          /* Update the sprite now. Next event may be from different  
> device. */
>

Tested, works.

Signed-off-by: Peter Hutterer <peter.hutterer at redhat.com>

Cheers,
  Peter



More information about the xorg mailing list