summaryrefslogtreecommitdiff
path: root/gtk/gtkwidgetpath.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-08-07 00:38:48 -0400
committerMatthias Clasen <mclasen@redhat.com>2012-08-07 00:38:48 -0400
commitf89d5c828038654802526c9ea68e6fb52fa461d3 (patch)
tree7dc99bf24c219756bfe3c9eb10e13ae4c584b2f5 /gtk/gtkwidgetpath.c
parente2c15e2791870c297bbc8e055dae359f9bc76a0c (diff)
downloadgtk+-f89d5c828038654802526c9ea68e6fb52fa461d3.tar.gz
Optimize gtk_widget_path_copy() by preallocating "elems" array
gtk_widget_path_copy() currently calls g_array_append_val() in a loop, which is inefficient due to reallocating the array's memory. Calling g_array_set_size() before entering the loop reduces the number of CPU cycles used by roughly 30%. Patch by John Lindgren, https://bugzilla.gnome.org/show_bug.cgi?id=679978
Diffstat (limited to 'gtk/gtkwidgetpath.c')
-rw-r--r--gtk/gtkwidgetpath.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/gtk/gtkwidgetpath.c b/gtk/gtkwidgetpath.c
index 00afbe0b9e..855902fd68 100644
--- a/gtk/gtkwidgetpath.c
+++ b/gtk/gtkwidgetpath.c
@@ -174,15 +174,16 @@ gtk_widget_path_copy (const GtkWidgetPath *path)
new_path = gtk_widget_path_new ();
+ g_array_set_size (new_path->elems, path->elems->len);
+
for (i = 0; i < path->elems->len; i++)
{
- GtkPathElement *elem, new;
+ GtkPathElement *elem, *dest;
elem = &g_array_index (path->elems, GtkPathElement, i);
+ dest = &g_array_index (new_path->elems, GtkPathElement, i);
- gtk_path_element_copy (&new, elem);
-
- g_array_append_val (new_path->elems, new);
+ gtk_path_element_copy (dest, elem);
}
return new_path;