1 commit dfec2c249915560cedd2b49326c6629ad8a0b0f2
2 Author: Jeff Muizelaar <jmuizelaar@mozilla.com>
3 Date: Tue Mar 2 16:01:41 2010 -0500
5 add a stash of cairo_t's
7 diff --git a/src/cairo.c b/src/cairo.c
8 index 3c9d892..4b27b83 100644
11 @@ -119,7 +119,63 @@ _cairo_set_error (cairo_t *cr, cairo_status_t status)
12 _cairo_status_set_error (&cr->status, _cairo_error (status));
16 +#if defined(_MSC_VER)
17 +#pragma intrinsic(_BitScanForward)
18 +static __forceinline int
23 + if (_BitScanForward(&i, x) != 0)
32 +/* We keep a small stash of contexts to reduce malloc pressure */
33 +#define CAIRO_STASH_SIZE 4
35 + cairo_t pool[CAIRO_STASH_SIZE];
42 + int avail, old, new;
44 + old = _context_stash.occupied;
45 + avail = ffs (~old) - 1;
46 + if (avail >= CAIRO_STASH_SIZE)
47 + return malloc (sizeof (cairo_t));
49 + new = old | (1 << avail);
50 + _context_stash.occupied = new;
52 + return &_context_stash.pool[avail];
56 +_context_put (cairo_t *cr)
58 + int old, new, avail;
60 + if (cr < &_context_stash.pool[0] ||
61 + cr >= &_context_stash.pool[CAIRO_STASH_SIZE])
67 + avail = ~(1 << (cr - &_context_stash.pool[0]));
68 + old = _context_stash.occupied;
70 + _context_stash.occupied = new;
73 /* We keep a small stash of contexts to reduce malloc pressure */
74 #define CAIRO_STASH_SIZE 4