[maemo-commits] [maemo-commits] r16315 - projects/haf/branches/hildon-fm/fremantle/hildon-fm
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu Oct 2 15:02:56 EEST 2008
- Previous message: [maemo-commits] r16314 - in projects/haf/branches/hildon-thumbnail/daemonize: . debian thumbs
- Next message: [maemo-commits] r16316 - in projects/haf/branches/hildon-fm/fremantle: . debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: rabinovich
Date: 2008-10-02 15:02:50 +0300 (Thu, 02 Oct 2008)
New Revision: 16315
Modified:
projects/haf/branches/hildon-fm/fremantle/hildon-fm/hildon-file-system-model.c
Log:
speeding up populating of a file system model
Modified: projects/haf/branches/hildon-fm/fremantle/hildon-fm/hildon-file-system-model.c
===================================================================
--- projects/haf/branches/hildon-fm/fremantle/hildon-fm/hildon-file-system-model.c 2008-10-02 11:48:59 UTC (rev 16314)
+++ projects/haf/branches/hildon-fm/fremantle/hildon-fm/hildon-file-system-model.c 2008-10-02 12:02:50 UTC (rev 16315)
@@ -174,7 +174,8 @@
hildon_file_system_model_add_node(GtkTreeModel * model,
GNode * parent_node,
GtkFileFolder * parent_folder,
- const GtkFilePath * path);
+ const GtkFilePath * path,
+ gboolean with_search);
static void hildon_file_system_model_remove_node_list(GtkTreeModel * model,
GNode * parent_node,
GSList * children);
@@ -213,6 +214,10 @@
static GtkTreePath *hildon_file_system_model_get_path(GtkTreeModel * model,
GtkTreeIter * iter);
+static GNode *
+hildon_file_system_model_search_path_internal (GNode *parent_node,
+ const GtkFilePath *path,
+ gboolean recursively);
#define CAST_GET_PRIVATE(o) \
((HildonFileSystemModelPrivate *) HILDON_FILE_SYSTEM_MODEL(o)->priv)
@@ -640,7 +645,7 @@
|| is_drive (model_node)
|| (model_node->folder
&& gtk_file_folder_is_finished_loading (model_node->folder)
- && model_node->pending_adds == 0));
+ && model_node->pending_adds == 0)); /* this is the only place pending_adds is checked, thus no need to know the exact amount, just equality to 0 */
}
static void emit_node_changed(GNode *node)
@@ -1156,6 +1161,8 @@
GtkFileFolder *monitor;
GSList *paths;
gpointer data;
+ GSList *next_path;
+ gboolean all_new;
} dfa_clos;
static gboolean
@@ -1171,14 +1178,34 @@
node = hildon_file_system_model_search_folder (c->monitor);
if (node)
{
+ gint i;
model_node = node->data;
- model_node->pending_adds -= g_slist_length (c->paths);
-
- hildon_file_system_model_files_added (c->monitor, c->paths, c->data);
+/* model_node->pending_adds -= g_slist_length (c->paths); */
+ model_node->pending_adds = 0; //no need to count
+ i = 0;
+ while (c->next_path && i < MAX_BATCH)
+ {
+ hildon_file_system_model_add_node (GTK_TREE_MODEL (model_node->model),
+ node,
+ c->monitor,
+ (GtkFilePath *) c->next_path->data,
+ !(c->all_new));
+ c->next_path = c->next_path->next;
+ i++;
+ }
+ model_node->pending_adds = (c->next_path != NULL)? 1 : 0;
}
GDK_THREADS_LEAVE ();
+ emit_node_changed (node);
+
+ if (is_node_loaded (node))
+ handle_finished_node (node);
+
+ if (c->next_path)
+ return TRUE;
+
g_object_unref (c->monitor);
gtk_file_paths_free (c->paths);
g_object_unref (c->data);
@@ -1190,7 +1217,8 @@
static void
delay_files_added (GtkFileFolder * monitor,
GSList * paths,
- gpointer data)
+ gpointer data,
+ gboolean all_new)
{
GNode *node;
HildonFileSystemModelNode *model_node;
@@ -1205,11 +1233,14 @@
g_object_ref (data);
model_node = node->data;
- model_node->pending_adds += g_slist_length (paths);
+/* model_node->pending_adds += g_slist_length (paths); */
+ model_node->pending_adds = 1; // it is faster than counting all items
c->monitor = monitor;
c->paths = paths;
c->data = data;
+ c->next_path = paths;
+ c->all_new = all_new;
g_idle_add (dfa_run, c);
}
@@ -1241,25 +1272,40 @@
{
gint i;
GtkTreeModel *model;
+ GtkFilePath *real_path;
+ gboolean all_new = TRUE;
model_node = node->data;
model = GTK_TREE_MODEL (model_node->model);
i = 0;
while (paths && i < MAX_BATCH)
- {
- hildon_file_system_model_add_node (model,
- node,
- monitor,
- (GtkFilePath *) paths->data);
- paths = paths->next;
- i++;
- }
+ {
+ if (model_node->location)
+ real_path = hildon_file_system_special_location_rewrite_path (model_node->location, CAST_GET_PRIVATE(model)->filesystem, paths->data);
+ else
+ real_path = gtk_file_path_copy (paths->data);
+
+ //search whether this node already exists
+ if (hildon_file_system_model_search_path_internal (node, real_path, FALSE)) {
+ //node already exists no need to add
+ all_new = FALSE;
+ } else {
+ hildon_file_system_model_add_node (model,
+ node,
+ monitor,
+ (GtkFilePath *) paths->data,
+ FALSE);
+ }
+ gtk_file_path_free(real_path);
+ paths = paths->next;
+ i++;
+ }
emit_node_changed (node);
if (paths)
- delay_files_added (monitor, paths, data);
+ delay_files_added (monitor, paths, data, all_new);
if (is_node_loaded (node))
handle_finished_node (node);
@@ -1789,7 +1835,8 @@
hildon_file_system_model_add_node (GtkTreeModel * model,
GNode * parent_node,
GtkFileFolder * parent_folder,
- const GtkFilePath *path)
+ const GtkFilePath *path,
+ gboolean with_search)
{
GNode *node;
HildonFileSystemModelPrivate *priv;
@@ -1853,6 +1900,7 @@
}
/* First check if this item is already part of the model */
+ if (with_search)
{
node =
hildon_file_system_model_search_path_internal (parent_node,
@@ -1920,7 +1968,7 @@
gtk_tree_model_row_inserted(model, tree_path, &iter);
gtk_tree_path_free(tree_path);
- if (g_node_n_children(parent_node) <= 1 &&
+ if (/* g_node_n_children(parent_node) <= 1 */ g_node_nth_child (parent_node, 1) == NULL /* means - no second child, should work faster */ &&
parent_node != priv->roots) {
/* Don't emit signals for fake root */
hildon_file_system_model_send_has_child_toggled(model,
@@ -2626,7 +2674,7 @@
else
{
hildon_file_system_model_add_node(GTK_TREE_MODEL(obj), priv->roots, NULL,
- file_path);
+ file_path, TRUE);
}
gtk_file_path_free(file_path);
- Previous message: [maemo-commits] r16314 - in projects/haf/branches/hildon-thumbnail/daemonize: . debian thumbs
- Next message: [maemo-commits] r16316 - in projects/haf/branches/hildon-fm/fremantle: . debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
