summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Rietveld <kris@lanedo.com>2013-06-12 19:32:03 +0200
committerKristian Rietveld <kris@lanedo.com>2013-07-17 10:26:53 +0200
commitfcd74a7e711cf19efe8c6932b463acf419bdb33b (patch)
tree9f80dcce48e6f79ff318f5f259aaadd460edd4c0
parent54410621434c229bb719c9dfd7253863e0579474 (diff)
downloadpango-fcd74a7e711cf19efe8c6932b463acf419bdb33b.tar.gz
Bypass line reordering if all runs have the same direction
-rw-r--r--pango/pango-layout.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index b1f63461..f1eed228 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -4882,8 +4882,36 @@ static void
pango_layout_line_reorder (PangoLayoutLine *line)
{
GSList *logical_runs = line->runs;
- line->runs = reorder_runs_recurse (logical_runs, g_slist_length (logical_runs));
- g_slist_free (logical_runs);
+ GSList *tmp_list;
+ gboolean all_even, all_odd;
+ guint8 level_or = 0, level_and = 1;
+ int length = 0;
+
+ /* Check if all items are in the same direction, in that case, the
+ * line does not need modification and we can avoid the expensive
+ * reorder runs recurse procedure.
+ */
+ for (tmp_list = logical_runs; tmp_list != NULL; tmp_list = tmp_list->next)
+ {
+ PangoLayoutRun *run = tmp_list->data;
+
+ level_or |= run->item->analysis.level;
+ level_and &= run->item->analysis.level;
+
+ length++;
+ }
+
+ /* If none of the levels had the LSB set, all numbers were even. */
+ all_even = (level_or & 0x1) == 0;
+
+ /* If all of the levels had the LSB set, all numbers were odd. */
+ all_odd = (level_and & 0x1) == 1;
+
+ if (!all_even && !all_odd)
+ {
+ line->runs = reorder_runs_recurse (logical_runs, length);
+ g_slist_free (logical_runs);
+ }
}
static int