Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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));
13 }
15 -#if HAS_ATOMIC_OPS
16 +#if defined(_MSC_VER)
17 +#pragma intrinsic(_BitScanForward)
18 +static __forceinline int
19 +ffs(int x)
20 +{
21 + unsigned long i;
22 +
23 + if (_BitScanForward(&i, x) != 0)
24 + return i + 1;
25 +
26 + return 0;
27 +}
28 +#endif
29 +
30 +
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;
38 +
39 +static cairo_t *
40 +_context_get (void)
41 +{
42 + int avail, old, new;
43 +
44 + old = _context_stash.occupied;
45 + avail = ffs (~old) - 1;
46 + if (avail >= CAIRO_STASH_SIZE)
47 + return malloc (sizeof (cairo_t));
48 +
49 + new = old | (1 << avail);
50 + _context_stash.occupied = new;
51 +
52 + return &_context_stash.pool[avail];
53 +}
54 +
55 +static void
56 +_context_put (cairo_t *cr)
57 +{
58 + int old, new, avail;
59 +
60 + if (cr < &_context_stash.pool[0] ||
61 + cr >= &_context_stash.pool[CAIRO_STASH_SIZE])
62 + {
63 + free (cr);
64 + return;
65 + }
66 +
67 + avail = ~(1 << (cr - &_context_stash.pool[0]));
68 + old = _context_stash.occupied;
69 + new = old & avail;
70 + _context_stash.occupied = new;
71 +}
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 {