summaryrefslogtreecommitdiff
path: root/pango/pango-ot-buffer.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-10-11 17:21:31 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-10-11 17:21:31 +0000
commit840d74b4712b8b77035cd8abbf72b3f6fe2e2c8c (patch)
treee8b7635f63e449b4fd63530da8f71f1f91561491 /pango/pango-ot-buffer.c
parent932a4bf0d8fe13bb657c09fb426cd85334159e79 (diff)
downloadpango-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
Diffstat (limited to 'pango/pango-ot-buffer.c')
-rw-r--r--pango/pango-ot-buffer.c44
1 files changed, 40 insertions, 4 deletions
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);
}