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



commit d861dd5df84c057335e2355e5c2d951e767ec1ce
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 290c6afdd0..6ae99f01a0 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -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);


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