diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2007-10-11 17:21:31 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2007-10-11 17:21:31 +0000 |
commit | 840d74b4712b8b77035cd8abbf72b3f6fe2e2c8c (patch) | |
tree | e8b7635f63e449b4fd63530da8f71f1f91561491 | |
parent | 932a4bf0d8fe13bb657c09fb426cd85334159e79 (diff) | |
download | pango-840d74b4712b8b77035cd8abbf72b3f6fe2e2c8c.tar.gz |
Bug 485566 – Cache one OpenType Buffer
2007-10-11 Behdad Esfahbod <behdad@gnome.org>
Bug 485566 – Cache one OpenType Buffer
* pango/pango-ot-buffer.c (acquire_buffer), (release_buffer),
(pango_ot_buffer_new), (pango_ot_buffer_destroy):
* pango/pango-ot-private.h:
Cache one HB_Buffer that is acquired using a lock. A new one is
created if the shared buffer is locked. The shared buffer is
cleared when released. May want to make it free shared buffer if
buffer->allocated is too large. Not sure.
svn path=/trunk/; revision=2443
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | pango/pango-ot-buffer.c | 44 | ||||
-rw-r--r-- | pango/pango-ot-private.h | 1 |
3 files changed, 53 insertions, 4 deletions
@@ -1,5 +1,17 @@ 2007-10-11 Behdad Esfahbod <behdad@gnome.org> + Bug 485566 – Cache one OpenType Buffer + + * pango/pango-ot-buffer.c (acquire_buffer), (release_buffer), + (pango_ot_buffer_new), (pango_ot_buffer_destroy): + * pango/pango-ot-private.h: + Cache one HB_Buffer that is acquired using a lock. A new one is + created if the shared buffer is locked. The shared buffer is + cleared when released. May want to make it free shared buffer if + buffer->allocated is too large. Not sure. + +2007-10-11 Behdad Esfahbod <behdad@gnome.org> + * pango/opentype/*: Mark internal symbols as HB_INTERNAL and define that to static in harfbuzz.c. diff --git a/pango/pango-ot-buffer.c b/pango/pango-ot-buffer.c index c10f1fc9..7feb10f0 100644 --- a/pango/pango-ot-buffer.c +++ b/pango/pango-ot-buffer.c @@ -24,6 +24,44 @@ #include "pango-ot-private.h" #include "pangofc-private.h" +/* cache a single HB_Buffer */ +static HB_Buffer cached_buffer = NULL; +G_LOCK_DEFINE_STATIC (cached_buffer); + +static HB_Buffer +acquire_buffer (gboolean *free_buffer) +{ + HB_Buffer buffer; + + if (G_LIKELY (G_TRYLOCK (cached_buffer))) + { + if (G_UNLIKELY (!cached_buffer)) + hb_buffer_new (&cached_buffer); + + buffer = cached_buffer; + *free_buffer = FALSE; + } + else + { + hb_buffer_new (&buffer); + *free_buffer = TRUE; + } + + return buffer; +} + +static void +release_buffer (HB_Buffer buffer, gboolean free_buffer) +{ + if (G_LIKELY (!free_buffer)) + { + hb_buffer_clear (buffer); + G_UNLOCK (cached_buffer); + } + else + hb_buffer_free (buffer); +} + /** * pango_ot_buffer_new * @font: a #PangoFcFont @@ -40,9 +78,7 @@ pango_ot_buffer_new (PangoFcFont *font) { PangoOTBuffer *buffer = g_slice_new (PangoOTBuffer); - if (hb_buffer_new (&buffer->buffer) != HB_Err_Ok) - g_warning ("Allocation of HB_Buffer failed"); /* this doesn't happen */ - + buffer->buffer = acquire_buffer (&buffer->should_free_hb_buffer); buffer->font = g_object_ref (font); buffer->applied_gpos = FALSE; buffer->rtl = FALSE; @@ -62,7 +98,7 @@ pango_ot_buffer_new (PangoFcFont *font) void pango_ot_buffer_destroy (PangoOTBuffer *buffer) { - hb_buffer_free (buffer->buffer); + release_buffer (buffer->buffer, buffer->should_free_hb_buffer); g_object_unref (buffer->font); g_slice_free (PangoOTBuffer, buffer); } diff --git a/pango/pango-ot-private.h b/pango/pango-ot-private.h index 88875e74..c56e0f26 100644 --- a/pango/pango-ot-private.h +++ b/pango/pango-ot-private.h @@ -86,6 +86,7 @@ struct _PangoOTRulesetClass struct _PangoOTBuffer { HB_Buffer buffer; + gboolean should_free_hb_buffer; PangoFcFont *font; guint rtl : 1; guint zero_width_marks : 1; |