summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-11-21 01:20:38 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-12-20 16:55:09 +0000
commit9d726712c22d8555d00b9f1ebacd5425dc9a5b61 (patch)
tree396d8db9bf19787866d95bca6aaa89aa8357ad0f
parent08530f5bf23386355a19b83db88173302c7a5300 (diff)
Allocate initial array of RegionInfo on the stack.
The region validate() code is frequently called by cairo as it is used to extract regions from the trapezoids for fast-paths through the drawing code and also for fast-path clipping and the RegionInfo allocation (as well as the pixman_rect_alloc during the final union) appears as a hot spot on application memory profiles.
-rw-r--r--pixman/pixman-region.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/pixman/pixman-region.c b/pixman/pixman-region.c
index 3718d657..01a28be7 100644
--- a/pixman/pixman-region.c
+++ b/pixman/pixman-region.c
@@ -1330,6 +1330,8 @@ validate (region_type_t * badreg,
int curBand;
} RegionInfo;
+ RegionInfo stack_regions[64];
+
int numRects; /* Original numRects for badreg */
RegionInfo *ri; /* Array of current regions */
int numRI; /* Number of entries used in ri */
@@ -1379,10 +1381,8 @@ validate (region_type_t * badreg,
/* Set up the first region to be the first rectangle in badreg */
/* Note that step 2 code will never overflow the ri[0].reg rects array */
- ri = (RegionInfo *) pixman_malloc_ab (4, sizeof(RegionInfo));
- if (!ri)
- return pixman_break (badreg);
- sizeRI = 4;
+ ri = stack_regions;
+ sizeRI = sizeof (stack_regions) / sizeof (stack_regions[0]);
numRI = 1;
ri[0].prevBand = 0;
ri[0].curBand = 0;
@@ -1451,9 +1451,16 @@ validate (region_type_t * badreg,
data_size = sizeRI * sizeof(RegionInfo);
if (data_size / sizeRI != sizeof(RegionInfo))
goto bail;
- rit = (RegionInfo *) realloc(ri, data_size);
- if (!rit)
- goto bail;
+ if (ri == stack_regions) {
+ rit = malloc (data_size);
+ if (!rit)
+ goto bail;
+ memcpy (rit, ri, numRI * sizeof (RegionInfo));
+ } else {
+ rit = (RegionInfo *) realloc(ri, data_size);
+ if (!rit)
+ goto bail;
+ }
ri = rit;
rit = &ri[numRI];
}
@@ -1509,13 +1516,15 @@ NextRect: ;
goto bail;
}
*badreg = ri[0].reg;
- free(ri);
+ if (ri != stack_regions)
+ free(ri);
good(badreg);
return ret;
bail:
for (i = 0; i < numRI; i++)
freeData(&ri[i].reg);
- free (ri);
+ if (ri != stack_regions)
+ free (ri);
return pixman_break (badreg);
}