[pango/wip/khaled/fribidi: 3/4] Avoid converting to UTF-32 for FriBiDi



commit 452efea4dc514889cfe08051aabf14260ee7c805
Author: Khaled Hosny <khaledhosny eglug org>
Date:   Tue Nov 14 15:12:23 2017 +0200

    Avoid converting to UTF-32 for FriBiDi
    
    Can’t tell if this is any faster, but does not look like a complex
    thing to do, so why not.

 pango/pango-bidi-type.c |   61 +++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c
index 65e2d02..b68f0d4 100644
--- a/pango/pango-bidi-type.c
+++ b/pango/pango-bidi-type.c
@@ -121,8 +121,13 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
                                    int             length,
                                    PangoDirection *pbase_dir)
 {
-  FriBidiParType fribidi_base_dir;
+  glong n_chars, i;
   guint8 *embedding_levels_list;
+  const gchar *p;
+  FriBidiParType fribidi_base_dir;
+  FriBidiCharType *types;
+  FriBidiLevel max_level;
+
 
   switch (*pbase_dir)
     {
@@ -144,36 +149,30 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
       break;
     }
 
-#ifdef FRIBIDI_HAVE_UTF8
-  {
-    if (length < 0)
-      length = strlen (text);
-    embedding_levels_list = (guint8 *) fribidi_log2vis_get_embedding_levels_new_utf8 (text, length, 
&fribidi_base_dir);
-  }
-#else
-  {
-    gunichar *text_ucs4;
-    glong n_chars;
-    FriBidiCharType *types;
-    FriBidiLevel max_level;
-
-    text_ucs4 = g_utf8_to_ucs4_fast (text, length, &n_chars);
-    types = g_new (FriBidiCharType, n_chars);
-    embedding_levels_list = g_new (guint8, n_chars);
-
-    fribidi_get_bidi_types (text_ucs4, n_chars, types);
-    max_level = fribidi_get_par_embedding_levels (types, n_chars,
-                                                 &fribidi_base_dir,
-                                                 (FriBidiLevel*)embedding_levels_list);
-    if (G_UNLIKELY(max_level == 0))
-      {
-        /* fribidi_get_par_embedding_levels failed, what should we do here? */
-      }
-
-    g_free (text_ucs4);
-    g_free (types);
-  }
-#endif
+  if (length < 0)
+    length = strlen (text);
+
+  n_chars = g_utf8_strlen (text, length);
+
+  types = g_new (FriBidiCharType, n_chars);
+  embedding_levels_list = g_new (guint8, n_chars);
+
+  for (i = 0, p = text; p < text + length; p = g_utf8_next_char(p), i++)
+    {
+      gunichar ch = g_utf8_get_char (p);
+      types[i] = fribidi_get_bidi_type (ch);
+    }
+
+  max_level = fribidi_get_par_embedding_levels (types, n_chars,
+                                               &fribidi_base_dir,
+                                               (FriBidiLevel*)embedding_levels_list);
+
+  g_free (types);
+
+  if (G_UNLIKELY(max_level == 0))
+    {
+      /* fribidi_get_par_embedding_levels failed, what should we do here? */
+    }
 
   *pbase_dir = (fribidi_base_dir == FRIBIDI_PAR_LTR) ?  PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]