[pango/wip/baedert/for-master] layout: Avoid getting the text length if we know it already



commit da2fccc395b6039a447dcc2c754ea8c4b1de4cf5
Author: Timm Bäder <mail baedert org>
Date:   Fri Apr 17 07:17:43 2020 +0200

    layout: Avoid getting the text length if we know it already

 pango/pango-layout.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index f6d37068..2de3f9eb 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -1125,15 +1125,22 @@ pango_layout_set_text (PangoLayout *layout,
   old_text = layout->text;
 
   if (length < 0)
-    layout->text = g_strdup (text);
+    {
+      layout->length = strlen (text);
+      layout->text = g_strndup (text, layout->length);
+    }
   else if (length > 0)
-    /* This is not exactly what we want.  We don't need the padding...
-     */
-    layout->text = g_strndup (text, length);
+    {
+      /* This is not exactly what we want.  We don't need the padding...
+       */
+      layout->length = length;
+      layout->text = g_strndup (text, length);
+    }
   else
-    layout->text = g_malloc0 (1);
-
-  layout->length = strlen (layout->text);
+    {
+      layout->length = 0;
+      layout->text = g_malloc0 (1);
+    }
 
   /* validate it, and replace invalid bytes with -1 */
   start = layout->text;


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