csshorthandproperty: Try to avoid allocating a GString for 1 font
authorTimm Bäder <mail@baedert.org>
Wed, 15 Jan 2020 12:18:16 +0000 (13:18 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 18 Jan 2020 07:49:52 +0000 (08:49 +0100)
gtk/gtkcssshorthandpropertyimpl.c

index 290c6afdd04de72449eedabd65e9b2c70fcef06a..6ae99f01a042b336c30f4e1d2d25064947bdec1f 100644 (file)
@@ -1143,18 +1143,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);