[gtk+] all: avoid boxed structs copying where possible (and 2)



commit fb9e4c2c3774fb4f02758dac053cfa44fe8a78cd
Author: Javier Jardón <jjardon gnome org>
Date:   Tue May 31 17:10:46 2011 +0200

    all: avoid boxed structs copying where possible (and 2)
    
    Use the GtkStyleContext accessors for boxed properties where possible,
    to reduce allocations.

 gtk/gtkcombobox.c |    7 ++-----
 gtk/gtklabel.c    |    7 ++-----
 gtk/gtkwidget.c   |   10 +++-------
 3 files changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 760e77f..b4f8211 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -5252,7 +5252,7 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
   gint                   font_size, arrow_size;
   PangoContext          *context;
   PangoFontMetrics      *metrics;
-  PangoFontDescription  *font_desc;
+  const PangoFontDescription *font_desc;
   GtkWidget             *child;
   gint                   minimum_width = 0, natural_width = 0;
   gint                   child_min, child_nat;
@@ -5277,9 +5277,7 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
   state = gtk_widget_get_state_flags (widget);
 
   get_widget_padding (widget, &padding);
-  gtk_style_context_get (style_context, state,
-                         "font", &font_desc,
-                         NULL);
+  font_desc = gtk_style_context_get_font (style_context, state);
 
   context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
   metrics = pango_context_get_metrics (context, font_desc,
@@ -5287,7 +5285,6 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
   font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
                             pango_font_metrics_get_descent (metrics));
   pango_font_metrics_unref (metrics);
-  pango_font_description_free (font_desc);
 
   arrow_size = MAX (arrow_size, font_size) * arrow_scaling;
 
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 169117f..972c110 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3200,19 +3200,16 @@ static PangoFontMetrics *
 get_font_metrics (PangoContext *context, GtkWidget *widget)
 {
   GtkStyleContext *style_context;
-  PangoFontDescription *font;
+  const PangoFontDescription *font;
   PangoFontMetrics *retval;
 
   style_context = gtk_widget_get_style_context (widget);
-  gtk_style_context_get (style_context, 0, "font", &font, NULL);
+  font = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
 
   retval = pango_context_get_metrics (context,
                                       font,
                                       pango_context_get_language (context));
 
-  if (font != NULL)
-    pango_font_description_free (font);
-
   return retval;
 }
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index cece4de..c2c68ba 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -9008,22 +9008,18 @@ static void
 update_pango_context (GtkWidget    *widget,
 		      PangoContext *context)
 {
-  PangoFontDescription *font_desc;
+  const PangoFontDescription *font_desc;
   GtkStyleContext *style_context;
 
   style_context = gtk_widget_get_style_context (widget);
 
-  gtk_style_context_get (style_context,
-			 gtk_widget_get_state_flags (widget),
-			 "font", &font_desc,
-			 NULL);
+  font_desc = gtk_style_context_get_font (style_context,
+                                          gtk_widget_get_state_flags (widget));
 
   pango_context_set_font_description (context, font_desc);
   pango_context_set_base_dir (context,
 			      gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
 			      PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
-
-  pango_font_description_free (font_desc);
 }
 
 static void



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