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



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

    Avoid converting to UTF-3 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 |   23 ++++++++++-------------
 1 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c
index 1c08dba..f831d27 100644
--- a/pango/pango-bidi-type.c
+++ b/pango/pango-bidi-type.c
@@ -144,24 +144,23 @@ 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;
+    glong n_chars, i;
     FriBidiCharType *types;
     FriBidiLevel max_level;
+    const char *p;
+
+    if (length < 0)
+      length = strlen (text);
+
+    n_chars = g_utf8_strlen (text, length);
 
-    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);
+    for (i = 0, p = text; p < text + length; p = g_utf8_next_char(p), i++)
+      types[i] = fribidi_get_bidi_type (g_utf8_get_char (p));
+
     max_level = fribidi_get_par_embedding_levels (types, n_chars,
                                                  &fribidi_base_dir,
                                                  (FriBidiLevel*)embedding_levels_list);
@@ -170,10 +169,8 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
       /* fribidi_get_par_embedding_levels failed, what should we do here? */
     }
 
-    g_free (text_ucs4);
     g_free (types);
   }
-#endif
 
   *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]