1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/cairo/add-a-stash-of-cairo_t-s.patch Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +commit dfec2c249915560cedd2b49326c6629ad8a0b0f2 1.5 +Author: Jeff Muizelaar <jmuizelaar@mozilla.com> 1.6 +Date: Tue Mar 2 16:01:41 2010 -0500 1.7 + 1.8 + add a stash of cairo_t's 1.9 + 1.10 +diff --git a/src/cairo.c b/src/cairo.c 1.11 +index 3c9d892..4b27b83 100644 1.12 +--- a/src/cairo.c 1.13 ++++ b/src/cairo.c 1.14 +@@ -119,7 +119,63 @@ _cairo_set_error (cairo_t *cr, cairo_status_t status) 1.15 + _cairo_status_set_error (&cr->status, _cairo_error (status)); 1.16 + } 1.17 + 1.18 +-#if HAS_ATOMIC_OPS 1.19 ++#if defined(_MSC_VER) 1.20 ++#pragma intrinsic(_BitScanForward) 1.21 ++static __forceinline int 1.22 ++ffs(int x) 1.23 ++{ 1.24 ++ unsigned long i; 1.25 ++ 1.26 ++ if (_BitScanForward(&i, x) != 0) 1.27 ++ return i + 1; 1.28 ++ 1.29 ++ return 0; 1.30 ++} 1.31 ++#endif 1.32 ++ 1.33 ++ 1.34 ++#if CAIRO_NO_MUTEX 1.35 ++/* We keep a small stash of contexts to reduce malloc pressure */ 1.36 ++#define CAIRO_STASH_SIZE 4 1.37 ++static struct { 1.38 ++ cairo_t pool[CAIRO_STASH_SIZE]; 1.39 ++ int occupied; 1.40 ++} _context_stash; 1.41 ++ 1.42 ++static cairo_t * 1.43 ++_context_get (void) 1.44 ++{ 1.45 ++ int avail, old, new; 1.46 ++ 1.47 ++ old = _context_stash.occupied; 1.48 ++ avail = ffs (~old) - 1; 1.49 ++ if (avail >= CAIRO_STASH_SIZE) 1.50 ++ return malloc (sizeof (cairo_t)); 1.51 ++ 1.52 ++ new = old | (1 << avail); 1.53 ++ _context_stash.occupied = new; 1.54 ++ 1.55 ++ return &_context_stash.pool[avail]; 1.56 ++} 1.57 ++ 1.58 ++static void 1.59 ++_context_put (cairo_t *cr) 1.60 ++{ 1.61 ++ int old, new, avail; 1.62 ++ 1.63 ++ if (cr < &_context_stash.pool[0] || 1.64 ++ cr >= &_context_stash.pool[CAIRO_STASH_SIZE]) 1.65 ++ { 1.66 ++ free (cr); 1.67 ++ return; 1.68 ++ } 1.69 ++ 1.70 ++ avail = ~(1 << (cr - &_context_stash.pool[0])); 1.71 ++ old = _context_stash.occupied; 1.72 ++ new = old & avail; 1.73 ++ _context_stash.occupied = new; 1.74 ++} 1.75 ++#elif HAS_ATOMIC_OPS 1.76 + /* We keep a small stash of contexts to reduce malloc pressure */ 1.77 + #define CAIRO_STASH_SIZE 4 1.78 + static struct {