summaryrefslogtreecommitdiff
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
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.
-rw-r--r--pango/Makefile.am1
-rw-r--r--pango/break.c13
-rw-r--r--pango/pango-context.c13
-rw-r--r--pango/pango-script-private.h56
-rw-r--r--pango/pango-script.c70
5 files changed, 101 insertions, 52 deletions
diff --git a/pango/Makefile.am b/pango/Makefile.am
index fff14dfb..c5153aec 100644
--- a/pango/Makefile.am
+++ b/pango/Makefile.am
@@ -92,6 +92,7 @@ libpango_1_0_la_SOURCES = \
pango-renderer.c \
pango-script.c \
pango-script-lang-table.h \
+ pango-script-private.h \
pango-tabs.c \
pango-utils.c \
reorder-items.c \
diff --git a/pango/break.c b/pango/break.c
index db3053a7..fa49b3fc 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -23,6 +23,7 @@
#include "pango-break.h"
#include "pango-modules.h"
+#include "pango-script-private.h"
#include <string.h>
#define PARAGRAPH_SEPARATOR 0x2029
@@ -1864,7 +1865,7 @@ pango_get_log_attrs (const char *text,
static guint engine_type_id = 0;
static guint render_type_id = 0;
PangoAnalysis analysis = { NULL };
- PangoScriptIter *iter;
+ PangoScriptIter iter;
g_return_if_fail (length == 0 || text != NULL);
g_return_if_fail (log_attrs != NULL);
@@ -1883,17 +1884,17 @@ pango_get_log_attrs (const char *text,
chars_broken = 0;
- iter = pango_script_iter_new (text, length);
- pango_script_iter_get_range (iter, &range_start, &range_end, &script);
+ _pango_script_iter_init (&iter, text, length);
+ pango_script_iter_get_range (&iter, &range_start, &range_end, &script);
range_engine = (PangoEngineLang*) pango_map_get_engine (lang_map, script);
g_assert (range_start == text);
- while (pango_script_iter_next (iter))
+ while (pango_script_iter_next (&iter))
{
const char *run_start, *run_end;
PangoEngineLang* run_engine;
- pango_script_iter_get_range (iter, &run_start, &run_end, &script);
+ pango_script_iter_get_range (&iter, &run_start, &run_end, &script);
run_engine = (PangoEngineLang*) pango_map_get_engine (lang_map, script);
g_assert (range_end == run_start);
@@ -1909,7 +1910,7 @@ pango_get_log_attrs (const char *text,
}
range_end = run_end;
}
- pango_script_iter_free (iter);
+ _pango_script_iter_fini (&iter);
g_assert (length < 0 || range_end == text + length);
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 9285581f..6c40a295 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -29,6 +29,7 @@
#include "pango-engine.h"
#include "pango-engine-private.h"
#include "pango-modules.h"
+#include "pango-script-private.h"
struct _PangoContext
{
@@ -685,7 +686,7 @@ struct _ItemizeState
ChangedFlags changed;
- PangoScriptIter *script_iter;
+ PangoScriptIter script_iter;
const char *script_end;
PangoScript script;
@@ -850,8 +851,8 @@ itemize_state_init (ItemizeState *state,
/* Initialize the script iterator
*/
- state->script_iter = pango_script_iter_new (text + start_index, length);
- pango_script_iter_get_range (state->script_iter, NULL,
+ _pango_script_iter_init (&state->script_iter, text + start_index, length);
+ pango_script_iter_get_range (&state->script_iter, NULL,
&state->script_end, &state->script);
update_end (state);
@@ -899,8 +900,8 @@ itemize_state_next (ItemizeState *state)
if (state->run_end == state->script_end)
{
- pango_script_iter_next (state->script_iter);
- pango_script_iter_get_range (state->script_iter, NULL,
+ pango_script_iter_next (&state->script_iter);
+ pango_script_iter_get_range (&state->script_iter, NULL,
&state->script_end, &state->script);
state->changed |= SCRIPT_CHANGED;
}
@@ -1410,7 +1411,7 @@ itemize_state_finish (ItemizeState *state)
g_free (state->embedding_levels);
if (state->free_attr_iter)
pango_attr_iterator_destroy (state->attr_iter);
- pango_script_iter_free (state->script_iter);
+ _pango_script_iter_fini (&state->script_iter);
pango_font_description_free (state->font_desc);
itemize_state_reset_shape_engines (state);
diff --git a/pango/pango-script-private.h b/pango/pango-script-private.h
new file mode 100644
index 00000000..b77209c6
--- /dev/null
+++ b/pango/pango-script-private.h
@@ -0,0 +1,56 @@
+/* Pango
+ * pango-script-private.h: Script tag handling, private definitions
+ *
+ * Copyright (C) 2002 Red Hat Software
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PANGO_SCRIPT_PRIVATE_H__
+#define __PANGO_SCRIPT_PRIVATE_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;
+};
+
+PangoScriptIter *
+_pango_script_iter_init (PangoScriptIter *iter,
+ const char *text,
+ int length);
+
+void
+_pango_script_iter_fini (PangoScriptIter *iter);
+
+#endif /* __PANGO_SCRIPT_PRIVATE_H__ */
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);
}