From 14de90b251dd8a6ff106e989580ef01cf5c2944d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 20 Feb 2013 12:00:54 +0000 Subject: [PATCH] sna/trapezoids: Embed a few cells into the stack Avoid an allocation in the common case where the set of trapezoids is fairly narrow. Signed-off-by: Chris Wilson --- src/sna/sna_trapezoids.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sna/sna_trapezoids.c b/src/sna/sna_trapezoids.c index 4ac8b8be..d0e1bd17 100644 --- a/src/sna/sna_trapezoids.c +++ b/src/sna/sna_trapezoids.c @@ -264,6 +264,7 @@ struct cell_list { int16_t count, size; struct cell *cells; + struct cell embedded[256]; }; /* The active list contains edges in the current scan line ordered by @@ -339,14 +340,17 @@ cell_list_init(struct cell_list *cells, int width) cell_list_rewind(cells); cells->count = 0; cells->size = width+1; - cells->cells = malloc(cells->size * sizeof(struct cell)); + cells->cells = cells->embedded; + if (cells->size > ARRAY_SIZE(cells->embedded)) + cells->cells = malloc(cells->size * sizeof(struct cell)); return cells->cells != NULL; } static void cell_list_fini(struct cell_list *cells) { - free(cells->cells); + if (cells->cells != cells->embedded) + free(cells->cells); } inline static void