[gnome-video-arcade] Index a GvaGameStore after we insert all the rows.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-video-arcade] Index a GvaGameStore after we insert all the rows.
- Date: Thu, 18 Feb 2010 04:51:51 +0000 (UTC)
commit 9628cce9e4dd9692506b0a1d3ff653551321686e
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Feb 17 23:41:18 2010 -0500
Index a GvaGameStore after we insert all the rows.
The index holds a mapping of ROM names to GtkTreeRowReferences. If we
build the index as we're inserting rows, then row references have to be
updated each time we insert a new row. Building the index after we're
done inserting rows yields a slight performance improvement, though not
as much as I was hoping.
src/gva-game-store.c | 35 +++++++++++++++++++++++++++++++----
1 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/src/gva-game-store.c b/src/gva-game-store.c
index 2947160..12dd7f3 100644
--- a/src/gva-game-store.c
+++ b/src/gva-game-store.c
@@ -42,6 +42,28 @@ game_store_get_index (GvaGameStore *game_store)
return index;
}
+static gboolean
+game_store_build_index_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ GHashTable *index)
+{
+ GvaGameStoreColumn column_id;
+ GtkTreeRowReference *reference;
+ gchar *name;
+
+ /* This is faster than calling gva_game_store_index_insert(). */
+
+ column_id = GVA_GAME_STORE_COLUMN_NAME;
+ gtk_tree_model_get (model, iter, column_id, &name, -1);
+ reference = gtk_tree_row_reference_new (model, path);
+
+ /* Index takes ownership of both the name and row reference. */
+ g_hash_table_insert (index, name, reference);
+
+ return FALSE;
+}
+
static gint
game_store_compare (GtkTreeModel *model,
GtkTreeIter *iter_a,
@@ -273,6 +295,7 @@ gva_game_store_new_from_query (const gchar *sql,
sqlite3_stmt *stmt;
GvaGameStoreColumn *column_ids;
GValue *column_values;
+ GHashTable *index;
const gchar *name;
gint n_columns, ii;
gint name_column = -1;
@@ -397,15 +420,19 @@ gva_game_store_new_from_query (const gchar *sql,
GTK_TREE_STORE (model), &iter,
(gint *) column_ids, column_values, n_columns + 1);
- /* Add an entry for this row to the index. */
- gva_game_store_index_insert (
- GVA_GAME_STORE (model), g_strdup (name), &iter);
-
/* Keep the UI responsive. */
if (gtk_main_iteration_do (FALSE))
goto fail;
}
+ /* Keeping GtkTreeRowReferences up-to-date while inserting
+ * potentially thousands of rows is very expensive. So we
+ * rebuild the index after we're done inserting rows. */
+ index = game_store_get_index (GVA_GAME_STORE (model));
+ gtk_tree_model_foreach (
+ model, (GtkTreeModelForeachFunc)
+ game_store_build_index_cb, index);
+
/* Query complete. */
if (errcode == SQLITE_DONE)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]