]> Pileus Git - ~andy/gtk/commitdiff
all: avoid boxed structs copying where possible
authorCosimo Cecchi <cosimoc@gnome.org>
Tue, 17 May 2011 18:20:31 +0000 (14:20 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Wed, 18 May 2011 14:27:21 +0000 (10:27 -0400)
Use the GtkStyleContext accessors for boxed properties where possible,
to reduce allocations.

https://bugzilla.gnome.org/show_bug.cgi?id=650420

gtk/gtkbutton.c
gtk/gtkcombobox.c
gtk/gtklabel.c
gtk/gtkmenubar.c
gtk/gtkstyle.c

index 9c5e7ab2419b067e5bc5c8309e6af3e6356b28d0..fe90025ca7c40262777ecc2ea26562739d220666 100644 (file)
@@ -1627,24 +1627,21 @@ _gtk_button_paint (GtkButton          *button,
       gint child_displacement_x;
       gint child_displacement_y;
       gboolean displace_focus;
-      GtkBorder *border;
+      GtkBorder border;
 
       gtk_style_context_get_style (context,
                                    "child-displacement-y", &child_displacement_y,
                                    "child-displacement-x", &child_displacement_x,
                                    "displace-focus", &displace_focus,
                                    NULL);
-
-      gtk_style_context_get (context, state,
-                             "border-width", &border,
-                             NULL);
+      gtk_style_context_get_border (context, state, &border);
 
       if (interior_focus)
         {
-          x += border->left + focus_pad;
-          y += border->top + focus_pad;
-          width -= (2 * focus_pad) + border->left + border->right;
-          height -=  (2 * focus_pad) + border->top + border->bottom;
+          x += border.left + focus_pad;
+          y += border.top + focus_pad;
+          width -= (2 * focus_pad) + border.left + border.right;
+          height -=  (2 * focus_pad) + border.top + border.bottom;
         }
       else
         {
@@ -1662,8 +1659,6 @@ _gtk_button_paint (GtkButton          *button,
 
       gtk_render_focus (context, cr,
                        x, y, width, height);
-
-      gtk_border_free (border);
     }
 
   gtk_style_context_restore (context);
index dfd27d8b99b833ecccaea49fc153e390e1e48c5b..760e77f25b1f345bf7f258ca034cf250aedf8944 100644 (file)
@@ -1282,17 +1282,13 @@ gtk_combo_box_state_flags_changed (GtkWidget     *widget,
         {
           GtkStyleContext *context;
           GtkStateFlags state;
-          GdkRGBA *color;
+          GdkRGBA color;
 
           context  = gtk_widget_get_style_context (widget);
           state = gtk_widget_get_state_flags (widget);
+          gtk_style_context_get_background_color (context, state, &color);
 
-          gtk_style_context_get (context, state,
-                                 "background-color", &color,
-                                 NULL);
-
-          gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
-          gdk_rgba_free (color);
+          gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
         }
     }
 
@@ -1374,17 +1370,14 @@ gtk_combo_box_style_updated (GtkWidget *widget)
   if (priv->tree_view && priv->cell_view)
     {
       GtkStyleContext *context;
-      GdkRGBA *color;
-
-      context = gtk_widget_get_style_context (widget);
-      gtk_style_context_get (context, 0,
-                             "background-color", &color,
-                             NULL);
+      GtkStateFlags state;
+      GdkRGBA color;
 
-      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view),
-                                         color);
+      context  = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+      gtk_style_context_get_background_color (context, state, &color);
 
-      gdk_rgba_free (color);
+      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
     }
 
   child = gtk_bin_get_child (GTK_BIN (combo_box));
@@ -3292,17 +3285,13 @@ gtk_combo_box_list_setup (GtkComboBox *combo_box)
     {
       GtkStyleContext *context;
       GtkStateFlags state;
-      GdkRGBA *color;
+      GdkRGBA color;
 
-      context = gtk_widget_get_style_context (widget);
+      context  = gtk_widget_get_style_context (widget);
       state = gtk_widget_get_state_flags (widget);
+      gtk_style_context_get_background_color (context, state, &color);
 
-      gtk_style_context_get (context, state,
-                             "background-color", &color,
-                             NULL);
-
-      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), color);
-      gdk_rgba_free (color);
+      gtk_cell_view_set_background_rgba (GTK_CELL_VIEW (priv->cell_view), &color);
 
       priv->box = gtk_event_box_new ();
       gtk_event_box_set_visible_window (GTK_EVENT_BOX (priv->box),
index 9b9752bc2d2eca084be7775d6926d0680360d391..0b35c96466b8a73c991d8166c2bfd9ce936ab61c 100644 (file)
@@ -4144,7 +4144,7 @@ gtk_label_draw (GtkWidget *widget,
 
   if (priv->text && (*priv->text != '\0'))
     {
-      GdkRGBA *bg_color, *fg_color;
+      GdkRGBA bg_color, fg_color;
 
       get_layout_location (label, &x, &y);
 
@@ -4192,23 +4192,18 @@ gtk_label_draw (GtkWidget *widget,
           if (gtk_widget_has_focus (widget))
             state |= GTK_STATE_FLAG_FOCUSED;
 
-          gtk_style_context_get (context, state,
-                                 "background-color", &bg_color,
-                                 "color", &fg_color,
-                                 NULL);
+          gtk_style_context_get_color (context, state, &fg_color);
+          gtk_style_context_get_background_color (context, state, &bg_color);
 
-          gdk_cairo_set_source_rgba (cr, bg_color);
+          gdk_cairo_set_source_rgba (cr, &bg_color);
           cairo_paint (cr);
 
-          gdk_cairo_set_source_rgba (cr, fg_color);
+          gdk_cairo_set_source_rgba (cr, &fg_color);
           cairo_move_to (cr, x, y);
           _gtk_pango_fill_layout (cr, priv->layout);
 
           cairo_restore (cr);
           cairo_region_destroy (clip);
-
-          gdk_rgba_free (bg_color);
-          gdk_rgba_free (fg_color);
         }
       else if (info)
         {
@@ -4230,7 +4225,7 @@ gtk_label_draw (GtkWidget *widget,
 
           if (active_link)
             {
-              GdkRGBA *bg_color;
+              GdkRGBA bg_color;
 
               range[0] = active_link->start;
               range[1] = active_link->end;
@@ -4256,11 +4251,9 @@ gtk_label_draw (GtkWidget *widget,
               else
                 state = GTK_STATE_FLAG_PRELIGHT;
 
-              gtk_style_context_get (context, state,
-                                     "background-color", &bg_color,
-                                     NULL);
+              gtk_style_context_get_background_color (context, state, &bg_color);
 
-              gdk_cairo_set_source_rgba (cr, bg_color);
+              gdk_cairo_set_source_rgba (cr, &bg_color);
               cairo_paint (cr);
 
               gdk_cairo_set_source_color (cr, text_color);
@@ -4269,7 +4262,6 @@ gtk_label_draw (GtkWidget *widget,
 
               gdk_color_free (link_color);
               gdk_color_free (visited_link_color);
-              gdk_rgba_free (bg_color);
 
               cairo_restore (cr);
             }
index 7c07aa63b17eaba0d25ad792ae2d9f231d4e6fd7..521f814d52b875b43ae424922cde048df3341b9b 100644 (file)
@@ -398,25 +398,22 @@ gtk_menu_bar_size_request (GtkWidget      *widget,
   if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
     {
       GtkStyleContext *context;
-      GtkBorder *border;
+      GtkBorder border;
 
       context = gtk_widget_get_style_context (widget);
-
-      gtk_style_context_get (context, 0,
-                             "border-width", &border,
-                             NULL);
+      gtk_style_context_get_border (context, gtk_widget_get_state_flags (widget),
+                                    &border);
 
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
         {
-          *minimum += border->left + border->right;
-          *natural += border->left + border->right;
+          *minimum += border.left + border.right;
+          *natural += border.left + border.right;
         }
       else
         {
-          *minimum += border->top + border->bottom;
-          *natural += border->top + border->bottom;
+          *minimum += border.top + border.bottom;
+          *natural += border.top + border.bottom;
         }
-      gtk_border_free (border);
     }
 }
 
@@ -503,19 +500,16 @@ gtk_menu_bar_size_allocate (GtkWidget     *widget,
       if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
        {
           GtkStyleContext *context;
-          GtkBorder *border;
+          GtkBorder border;
 
           context = gtk_widget_get_style_context (widget);
-          gtk_style_context_get (context, 0,
-                                 "border-width", &border,
-                                 NULL);
-
-          remaining_space.x += border->left;
-          remaining_space.y += border->top;
-          remaining_space.width -= border->left + border->right;
-          remaining_space.height -= border->top + border->bottom;
+          gtk_style_context_get_border (context, gtk_widget_get_state_flags (widget),
+                                        &border);
 
-          gtk_border_free (border);
+          remaining_space.x += border.left;
+          remaining_space.y += border.top;
+          remaining_space.width -= border.left + border.right;
+          remaining_space.height -= border.top + border.bottom;
        }
       
       requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize));
index cf88d1d07a601dd8a48a9d9a0f10301ed86d4261..f7e987a3479aef5098ab58a57ba7251d85d25951 100644 (file)
@@ -685,7 +685,7 @@ gtk_style_update_from_context (GtkStyle *style)
 {
   GtkStylePrivate *priv;
   GtkStateType state;
-  GtkBorder *padding;
+  GtkBorder padding;
   gint i;
 
   priv = GTK_STYLE_GET_PRIVATE (style);
@@ -721,16 +721,11 @@ gtk_style_update_from_context (GtkStyle *style)
 
   gtk_style_context_get (priv->context, 0,
                          "font", &style->font_desc,
-                         "padding", &padding,
                          NULL);
+  gtk_style_context_get_padding (priv->context, 0, &padding);
 
-  if (padding)
-    {
-      style->xthickness = padding->left;
-      style->ythickness = padding->top;
-
-      gtk_border_free (padding);
-    }
+  style->xthickness = padding.left;
+  style->ythickness = padding.top;
 
   for (i = 0; i < 5; i++)
     {