From: Clarke B. <cl...@vo...> - 2006-10-17 10:17:33
|
I recently had some spare time and decided to take gtkpod through a bit of valgrind fun. I found out an unusually large amount of time was spent in gtkpod_tracks_statusbar_update, due to it calling tm_get_nr_of_tracks, which grabbed an iterator on the gtk tree model and counted all of the tracks manually on each update. The following patch switches the iterator to a call to gtk_tree_model_iter_n_children (), saving a considerable amount of processing for large databases. ~Clarke Brunsdon Index: src/display_songs.c =================================================================== RCS file: /cvsroot/gtkpod/gtkpod/src/display_songs.c,v retrieving revision 1.112 diff -u -r1.112 display_songs.c --- src/display_songs.c 21 Sep 2006 15:03:13 -0000 1.112 +++ src/display_songs.c 16 Oct 2006 17:18:30 -0000 @@ -1154,18 +1154,13 @@ { GtkTreeIter i; guint result = 0; - gboolean valid = FALSE; GtkTreeModel *tm = NULL; if((tm = gtk_tree_view_get_model(GTK_TREE_VIEW(track_treeview)))) { - if((valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tm),&i))) - { - result++; - while((valid = gtk_tree_model_iter_next(tm,&i))) - result++; - } + result = gtk_tree_model_iter_n_children (tm, (void*)NULL); } + return(result); } |