Bug 901583: Webrtc updated to 4563; pull made Sat Aug 17 11:00:00 EDT 2013 rs=jesup
[gecko.git] / gfx / cairo / add-a-stash-of-cairo_t-s.patch
blobc6fcdd9d881ad2ec56c8a2d088d81a39f6310ab1
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
9 --- a/src/cairo.c
10 +++ b/src/cairo.c
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));
15 -#if HAS_ATOMIC_OPS
16 +#if defined(_MSC_VER)
17 +#pragma intrinsic(_BitScanForward)
18 +static __forceinline int
19 +ffs(int x)
21 + unsigned long i;
23 + if (_BitScanForward(&i, x) != 0)
24 + return i + 1;
26 + return 0;
28 +#endif
31 +#if CAIRO_NO_MUTEX
32 +/* We keep a small stash of contexts to reduce malloc pressure */
33 +#define CAIRO_STASH_SIZE 4
34 +static struct {
35 + cairo_t pool[CAIRO_STASH_SIZE];
36 + int occupied;
37 +} _context_stash;
39 +static cairo_t *
40 +_context_get (void)
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];
55 +static void
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])
62 + {
63 + free (cr);
64 + return;
65 + }
67 + avail = ~(1 << (cr - &_context_stash.pool[0]));
68 + old = _context_stash.occupied;
69 + new = old & avail;
70 + _context_stash.occupied = new;
72 +#elif HAS_ATOMIC_OPS
73 /* We keep a small stash of contexts to reduce malloc pressure */
74 #define CAIRO_STASH_SIZE 4
75 static struct {