summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-02-20 12:00:54 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2013-02-20 12:00:54 +0000
commit14de90b251dd8a6ff106e989580ef01cf5c2944d (patch)
tree13840655697e8a3b34df1917dbf16baf4139bf03
parent3eca4ea1a5d8ce04598b8d42e93e0dcb93e42e9a (diff)
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 <chris@chris-wilson.co.uk>
-rw-r--r--src/sna/sna_trapezoids.c8
1 files 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