The probability that a node of level L is generated is
0.25^(L-1) * 0.75. It means, a node of level 15 or
more will be used with a probability of about 3 * 10^-9.
That's really rare...
Actually that's not still true, because the level of a new
node is capped by current max-level plus one. So to really
get a node with a level of 15 one should first get a node
of level 2, then 3, then 4, ..., finally 15. Now that's
REALLY rare.
And guess what, the skiplist only start behaving bad with a
max level cap of MAX_LEVEL when having on the order of
4**MAX_LEVEL items in it. I really hope we don't get there.
Most memory allocators allocate in multiples of twice the size of
a pointer. So there is no point in keeping freelists for both
even and odd levels. We now round odd levels up to the next
even level for freelist computations. This reduces the number of
node mallocations.
Reading the code, MAX_LEVEL is in fact what could have been named
MAX_NUM_LEVELS. That is, it is maximum possible level plus one.
All code is correct: it uses MAX_LEVEL as array size and never produces
a level of MAX_LEVEL. The comment is fixed.
Most of the time pixman_region_init is called without any extents, and
followed by a pixman_region_union_rect, used to used to initialize
rectangular regions. pixman_region_union_rect is not that cheap, but
the sequence is called quite often. So it should be worth introducing
a specialized and fast function for this sequence.
This introduces pixman_region_init_rect. This new function makes
_cairo_region_init_from_rectangle obsolete.
Also removes the extent argument from pixman_region_init as it was
called with NULL most of the time. A pixman_region_init_with_extents
is added for the general case.
This ensures that error due to double-to-float conversion
does not accumulate; the position of any glyph will be off by
at most one double-to-float conversion error.
Previously, a failure in _cairo_win32_scaled_font_init_glyph_path leading
to the CLEANUP_FONT label would set the path into the glyph, then destroy
the path, and return an error status, (which in turn would cause a double
free when the glyph was destroyed).
The double-free apparently leads to a crash in some cases, as described
here:
SVG/Cairo related crash when opening specific webpage
https://bugzilla.mozilla.org/show_bug.cgi?id=376498
This should eliminate the double-free, but does not address the original
error case, (attempting to get a path from a bitmap font?).
This is necessary to avoid many portability problems as cairoint.h includes
config.h. Without a test, we will regress again, hence add it.
The inclusion idiom for cairo now is:
#include "cairoint.h"
#include "cairo-something.h"
#include "cairo-anotherthing-private.h"
#include <some-library.h>
#include <other-library/other-file.h>
Moreover, some standard headers files are included from cairoint.h and need
not be included again.
Previously, the convention was that static ones started with cairo_, but
renamed to start with _cairo_ when they were needed from other files and
became cairo_private instead of static...
This is error prune indeed, and two symbols were already violating. Now
all nil objects start with _cairo_.
Frequently cairo_set_source_rgb[a]() is used to replace the current
solid-pattern source with a new one of a different colour. The current
pattern is very likely to be unshared and unmodified and so it is likely
just to be immediately freed [or rather simply moved to recently freed
cache]. However as the last active pattern it is likely to cache-warm and
suitable to satisfy the forthcoming allocation. So by setting the current
pattern to 'none' we can move the pattern to the freed list before we
create the new pattern and hopefully immediately reuse it.
Unfortunately one cannot cache live patterns and return a fresh reference
instead of creating new ones as patterns can be modified by the user and
so cannot be transparently shared between different users. However,
solid colour allocation is still a frequent operation, so we maintain a
small cache of recently freed patterns to reduce the malloc pressure.
We use a small cache of size 16 for patterns created from solid colors,
e.g. cairo_set_source_rgb(). This helps with toolkits that draw many
widgets using the same colour scheme.
The cache uses a static index variable, which itself acts like a cache
of size 1, remembering the most recently used colour. So repeated
lookups for the same colour hit immediately. If that fails, the cache
is searched linearly, and if that fails too, a new pattern is created
and a random member of the cache is evicted.
All mutex declarations have been moved to cairo-mutex-list.h.
This should avoid breaking of less frequently tested backends,
when mutexes are introduced or when existing mutexes are renamed.
Instead of initializing mutexes on library startup, mutexes are
lazily initialized within the few entry points of now by calling
CAIRO_MUTEX_INITIALIZE(). Currently only the OS/2 backend takes
care about releasing global mutexes. Therefore there is no counter
part of that macro for finalizing all global mutexes yet - but
as cairo-backend-os2.c shows such a function would be quite
easy to implement.
We detect an error in the surface before calling into private surface-modifying
functions, (such as _cairo_surface_set_font_options), that don't have the
nil-surface protection of public functions.
This should fix the problem reported (again) in this bug report:
cairo crashes in cairo_create_simular if nil surface returned by other->backend->create_similar
https://bugs.freedesktop.org/show_bug.cgi?id=9844
Though I haven't succeeded in replicating the bug yet, (perhaps a system
difference in allowing writes to read-only memory or not, or something
like that).