summaryrefslogtreecommitdiff
path: root/pango/pango-script.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-03-18 13:02:13 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2009-03-20 08:44:40 +0000
commit698203ab28bc679c2e62a2452a79d5785fd46ca7 (patch)
treea2d0086444a6a25500283210cd340daca899ece7 /pango/pango-script.c
parent3241972c4f4d9c1d98d166c38cb0d7b12afb5545 (diff)
downloadpango-698203ab28bc679c2e62a2452a79d5785fd46ca7.tar.gz
[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.
Diffstat (limited to 'pango/pango-script.c')
-rw-r--r--pango/pango-script.c70
1 files changed, 30 insertions, 40 deletions
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 <string.h>
#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);
}