From 698203ab28bc679c2e62a2452a79d5785fd46ca7 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 18 Mar 2009 13:02:13 +0000 Subject: [pango] Allocate PangoScriptIter on stack. Move the PangoScriptIter structure definition to a private header file, so that we can embed the iterator within other structures or allocate a local iterator on the stack. This eliminates the frequent short-lived allocations associated with the iterator. --- pango/pango-script.c | 70 ++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'pango/pango-script.c') diff --git a/pango/pango-script.c b/pango/pango-script.c index 862c8475..605e46e2 100644 --- a/pango/pango-script.c +++ b/pango/pango-script.c @@ -58,29 +58,7 @@ #include #include "pango-script.h" - -#define PAREN_STACK_DEPTH 128 - -typedef struct _ParenStackEntry ParenStackEntry; - -struct _ParenStackEntry -{ - int pair_index; - PangoScript script_code; -}; - -struct _PangoScriptIter -{ - const gchar *text_start; - const gchar *text_end; - - const gchar *script_start; - const gchar *script_end; - PangoScript script_code; - - ParenStackEntry paren_stack[PAREN_STACK_DEPTH]; - int paren_sp; -}; +#include "pango-script-private.h" /** * pango_script_for_unichar: @@ -106,6 +84,28 @@ pango_script_for_unichar (gunichar ch) /**********************************************************************/ +PangoScriptIter * +_pango_script_iter_init (PangoScriptIter *iter, + const char *text, + int length) +{ + iter->text_start = text; + if (length >= 0) + iter->text_end = text + length; + else + iter->text_end = text + strlen (text); + + iter->script_start = text; + iter->script_end = text; + iter->script_code = PANGO_SCRIPT_COMMON; + + iter->paren_sp = -1; + + pango_script_iter_next (iter); + + return iter; +} + /** * pango_script_iter_new: * @text: a UTF-8 string @@ -114,7 +114,7 @@ pango_script_for_unichar (gunichar ch) * Create a new #PangoScriptIter, used to break a string of * Unicode into runs by text. No copy is made of @text, so * the caller needs to make sure it remains valid until - * the iterator is freed with pango_script_iter_free ().x + * the iterator is freed with pango_script_iter_free(). * * Return value: the new script iterator, initialized * to point at the first range in the text, which should be @@ -127,23 +127,12 @@ PangoScriptIter * pango_script_iter_new (const char *text, int length) { - PangoScriptIter *iter = g_slice_new (PangoScriptIter); - - iter->text_start = text; - if (length >= 0) - iter->text_end = text + length; - else - iter->text_end = text + strlen (text); - - iter->script_start = text; - iter->script_end = text; - iter->script_code = PANGO_SCRIPT_COMMON; - - iter->paren_sp = -1; - - pango_script_iter_next (iter); + return _pango_script_iter_init (g_slice_new (PangoScriptIter), text, length); +} - return iter; +void +_pango_script_iter_fini (PangoScriptIter *iter) +{ } /** @@ -157,6 +146,7 @@ pango_script_iter_new (const char *text, void pango_script_iter_free (PangoScriptIter *iter) { + _pango_script_iter_fini (iter); g_slice_free (PangoScriptIter, iter); } -- cgit v1.2.1