summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2020-04-17 07:17:43 +0200
committerTimm Bäder <mail@baedert.org>2020-06-08 19:16:08 +0200
commit0efa31306ce04b3b3a6c8e2da96af32834ac860a (patch)
treef6b326c74c5a07b229a63251d43ffb232e698da6
parentc802c85d0ed07cc1dae5db8f1991d82ec45bf1bd (diff)
downloadpango-0efa31306ce04b3b3a6c8e2da96af32834ac860a.tar.gz
layout: Avoid getting the text length if we know it already
-rw-r--r--pango/pango-layout.c21
1 files 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;