[gtk/wip/baedert/css-values: 9/13] csshorthandproperty: Try to avoid allocating a GString for 1 font



commit b27f2160e774aefc35967c244e9d22232e548d96
Author: Timm Bäder <mail baedert org>
Date:   Wed Jan 15 13:18:16 2020 +0100

    csshorthandproperty: Try to avoid allocating a GString for 1 font

 gtk/gtkcssshorthandpropertyimpl.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 528fe5bb15..08330360f3 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -1144,18 +1144,26 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
   v = (* query_func) (GTK_CSS_PROPERTY_FONT_FAMILY, query_data);
   if (v)
     {
-      int i;
-      GString *s = g_string_new ("");
+      if (_gtk_css_array_value_get_n_values (v) > 1)
+        {
+          int i;
+          GString *s = g_string_new ("");
+
+          for (i = 0; i < _gtk_css_array_value_get_n_values (v); i++)
+            {
+              if (i > 0)
+                g_string_append (s, ",");
+              g_string_append (s, _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, i)));
+            }
 
-      for (i = 0; i < _gtk_css_array_value_get_n_values (v); i++)
+          pango_font_description_set_family (description, s->str);
+          g_string_free (s, TRUE);
+        }
+      else
         {
-          if (i > 0)
-            g_string_append (s, ",");
-          g_string_append (s, _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, i)));
+          pango_font_description_set_family (description,
+                                             _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, 
0)));
         }
-
-      pango_font_description_set_family (description, s->str);
-      g_string_free (s, TRUE);
     }
 
   v = (* query_func) (GTK_CSS_PROPERTY_FONT_SIZE, query_data);


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