mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 12:18:01 +02:00
Iterate over hash table using foreach() in destructors.
Don't use the remarkably inefficient _cairo_hash_table_random_entry() to remove all entries from the hash table!
This commit is contained in:
parent
1c4ea84b24
commit
f5274f5847
2 changed files with 33 additions and 35 deletions
|
|
@ -665,19 +665,20 @@ cff_dict_write (cairo_hash_table_t *dict, cairo_array_t *output)
|
|||
return write_info.status;
|
||||
}
|
||||
|
||||
static void
|
||||
_cff_dict_entry_pluck (void *_entry, void *dict)
|
||||
{
|
||||
cff_dict_operator_t *entry = _entry;
|
||||
|
||||
_cairo_hash_table_remove (dict, &entry->base);
|
||||
free (entry->operand);
|
||||
free (entry);
|
||||
}
|
||||
|
||||
static void
|
||||
cff_dict_fini (cairo_hash_table_t *dict)
|
||||
{
|
||||
cff_dict_operator_t *entry;
|
||||
|
||||
while (1) {
|
||||
entry = _cairo_hash_table_random_entry (dict, NULL);
|
||||
if (entry == NULL)
|
||||
break;
|
||||
free (entry->operand);
|
||||
_cairo_hash_table_remove (dict, (cairo_hash_entry_t *) entry);
|
||||
free (entry);
|
||||
}
|
||||
_cairo_hash_table_foreach (dict, _cff_dict_entry_pluck, dict);
|
||||
_cairo_hash_table_destroy (dict);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -222,34 +222,35 @@ FAIL:
|
|||
cairo_ft_unscaled_font_map = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_cairo_ft_unscaled_font_map_pluck_entry (void *entry, void *closure)
|
||||
{
|
||||
cairo_ft_unscaled_font_t *unscaled = entry;
|
||||
cairo_ft_unscaled_font_map_t *font_map = closure;
|
||||
|
||||
_cairo_hash_table_remove (font_map->hash_table,
|
||||
&unscaled->base.hash_entry);
|
||||
|
||||
_font_map_release_face_lock_held (font_map, unscaled);
|
||||
_cairo_ft_unscaled_font_fini (unscaled);
|
||||
free (unscaled);
|
||||
}
|
||||
|
||||
static void
|
||||
_cairo_ft_unscaled_font_map_destroy (void)
|
||||
{
|
||||
cairo_ft_unscaled_font_t *unscaled;
|
||||
cairo_ft_unscaled_font_map_t *font_map;
|
||||
|
||||
CAIRO_MUTEX_LOCK (_cairo_ft_unscaled_font_map_mutex);
|
||||
font_map = cairo_ft_unscaled_font_map;
|
||||
cairo_ft_unscaled_font_map = NULL;
|
||||
CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex);
|
||||
|
||||
if (cairo_ft_unscaled_font_map) {
|
||||
font_map = cairo_ft_unscaled_font_map;
|
||||
|
||||
/* This is rather inefficient, but destroying the hash table
|
||||
* is something we only do during debugging, (during
|
||||
* cairo_debug_reset_static_data), when efficiency is not
|
||||
* relevant. */
|
||||
while (1) {
|
||||
unscaled = _cairo_hash_table_random_entry (font_map->hash_table,
|
||||
NULL);
|
||||
if (unscaled == NULL)
|
||||
break;
|
||||
_cairo_hash_table_remove (font_map->hash_table,
|
||||
&unscaled->base.hash_entry);
|
||||
|
||||
_font_map_release_face_lock_held (font_map, unscaled);
|
||||
_cairo_ft_unscaled_font_fini (unscaled);
|
||||
free (unscaled);
|
||||
}
|
||||
|
||||
if (font_map != NULL) {
|
||||
_cairo_hash_table_foreach (font_map->hash_table,
|
||||
_cairo_ft_unscaled_font_map_pluck_entry,
|
||||
font_map);
|
||||
assert (font_map->num_open_faces == 0);
|
||||
|
||||
FT_Done_FreeType (font_map->ft_library);
|
||||
|
|
@ -257,11 +258,7 @@ _cairo_ft_unscaled_font_map_destroy (void)
|
|||
_cairo_hash_table_destroy (font_map->hash_table);
|
||||
|
||||
free (font_map);
|
||||
|
||||
cairo_ft_unscaled_font_map = NULL;
|
||||
}
|
||||
|
||||
CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex);
|
||||
}
|
||||
|
||||
static cairo_ft_unscaled_font_map_t *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue