[pango/tab-speedup: 1/2] layout: Small optimization




commit 0254870fe834465c58f5a7d0b39fa32ffe88ad8d
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 1 23:46:04 2021 -0500

    layout: Small optimization
    
    Don't calculate line width the hard way when
    we can do it much easier.

 pango/pango-layout.c          | 28 +++-------------------------
 tests/layouts/valid-12.layout | 14 +++++++-------
 tests/layouts/valid-13.layout | 14 +++++++-------
 3 files changed, 17 insertions(+), 39 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index a9d07940..6bdf5b43 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3269,6 +3269,7 @@ pango_layout_line_leaked (PangoLayoutLine *line)
 
 static void shape_tab (PangoLayoutLine  *line,
                        LastTabState     *tab_state,
+                       int               current_width,
                        PangoItem        *item,
                        PangoGlyphString *glyphs);
 
@@ -3456,27 +3457,6 @@ get_tab_pos (PangoLayoutLine *line,
   *tab_pos -= offset;
 }
 
-static int
-line_width (PangoLayoutLine *line)
-{
-  GSList *l;
-  int i;
-  int width = 0;
-
-  /* Compute the width of the line currently - inefficient, but easier
-   * than keeping the current width of the line up to date everywhere
-   */
-  for (l = line->runs; l; l = l->next)
-    {
-      PangoLayoutRun *run = l->data;
-
-      for (i = 0; i < run->glyphs->num_glyphs; i++)
-        width += run->glyphs->glyphs[i].geometry.width;
-    }
-
-  return width;
-}
-
 static gboolean
 showing_space (const PangoAnalysis *analysis)
 {
@@ -3513,17 +3493,15 @@ struct _LastTabState {
 static void
 shape_tab (PangoLayoutLine  *line,
            LastTabState     *tab_state,
+           int               current_width,
            PangoItem        *item,
            PangoGlyphString *glyphs)
 {
   int i, space_width;
-  int current_width;
   int tab_pos;
   PangoTabAlign tab_align;
   gunichar tab_decimal;
 
-  current_width = line_width (line);
-
   pango_glyph_string_set_size (glyphs, 1);
 
   if (showing_space (&item->analysis))
@@ -3707,7 +3685,7 @@ shape_run (PangoLayoutLine *line,
   PangoGlyphString *glyphs = pango_glyph_string_new ();
 
   if (layout->text[item->offset] == '\t')
-    shape_tab (line, &state->last_tab, item, glyphs);
+    shape_tab (line, &state->last_tab, state->line_width - state->remaining_width, item, glyphs);
   else
     {
       PangoShapeFlags shape_flags = PANGO_SHAPE_NONE;
diff --git a/tests/layouts/valid-12.layout b/tests/layouts/valid-12.layout
index 247b374e..44eb064b 100644
--- a/tests/layouts/valid-12.layout
+++ b/tests/layouts/valid-12.layout
@@ -52,7 +52,7 @@
     "is-wrapped" : true,
     "is-ellipsized" : false,
     "unknown-glyphs" : 1,
-    "width" : 179200,
+    "width" : 202752,
     "height" : 38912,
     "log-attrs" : [
       {
@@ -258,7 +258,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -330,7 +330,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -402,7 +402,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 44032,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -554,7 +554,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -626,7 +626,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 46080,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -698,7 +698,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
diff --git a/tests/layouts/valid-13.layout b/tests/layouts/valid-13.layout
index b557a278..57dad35d 100644
--- a/tests/layouts/valid-13.layout
+++ b/tests/layouts/valid-13.layout
@@ -53,7 +53,7 @@
     "is-wrapped" : false,
     "is-ellipsized" : false,
     "unknown-glyphs" : 1,
-    "width" : 315392,
+    "width" : 386048,
     "height" : 19456,
     "log-attrs" : [
       {
@@ -271,7 +271,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -355,7 +355,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -439,7 +439,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 44032,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -607,7 +607,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 17408,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -691,7 +691,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 46080,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }
@@ -775,7 +775,7 @@
             "glyphs" : [
               {
                 "glyph" : 268435455,
-                "width" : 43008,
+                "width" : 51200,
                 "is-cluster-start" : true,
                 "log-cluster" : 0
               }


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