[pango/wip-bitmatrix] context: Avoid extra allocations in font cache
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/wip-bitmatrix] context: Avoid extra allocations in font cache
- Date: Sun, 23 Aug 2020 01:09:46 +0000 (UTC)
commit ce94704f045296a51f765150e0d51d29651b63e1
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 22 19:00:54 2020 -0400
context: Avoid extra allocations in font cache
There's no need to allocate an extra struct for
each font cache entry.
pango/pango-context.c | 36 ++++++------------------------------
1 file changed, 6 insertions(+), 30 deletions(-)
---
diff --git a/pango/pango-context.c b/pango/pango-context.c
index bebe804a..822025b5 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -626,10 +626,6 @@ typedef struct {
GHashTable *hash;
} FontCache;
-typedef struct {
- PangoFont *font;
-} FontElement;
-
static void
font_cache_destroy (FontCache *cache)
{
@@ -637,14 +633,6 @@ font_cache_destroy (FontCache *cache)
g_slice_free (FontCache, cache);
}
-static void
-font_element_destroy (FontElement *element)
-{
- if (element->font)
- g_object_unref (element->font);
- g_slice_free (FontElement, element);
-}
-
static FontCache *
get_font_cache (PangoFontset *fontset)
{
@@ -660,7 +648,7 @@ retry:
{
cache = g_slice_new (FontCache);
cache->hash = g_hash_table_new_full (g_direct_hash, NULL,
- NULL, (GDestroyNotify)font_element_destroy);
+ NULL, (GDestroyNotify)g_object_unref);
if (!g_object_replace_qdata (G_OBJECT (fontset), cache_quark, NULL,
cache, (GDestroyNotify)font_cache_destroy,
NULL))
@@ -678,28 +666,16 @@ font_cache_get (FontCache *cache,
gunichar wc,
PangoFont **font)
{
- FontElement *element;
-
- element = g_hash_table_lookup (cache->hash, GUINT_TO_POINTER (wc));
- if (element)
- {
- *font = element->font;
-
- return TRUE;
- }
- else
- return FALSE;
+ *font = g_hash_table_lookup (cache->hash, GUINT_TO_POINTER (wc));
+ return *font != NULL;
}
static void
font_cache_insert (FontCache *cache,
- gunichar wc,
- PangoFont *font)
+ gunichar wc,
+ PangoFont *font)
{
- FontElement *element = g_slice_new (FontElement);
- element->font = font ? g_object_ref (font) : NULL;
-
- g_hash_table_insert (cache->hash, GUINT_TO_POINTER (wc), element);
+ g_hash_table_insert (cache->hash, GUINT_TO_POINTER (wc), g_object_ref (font));
}
/**********************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]