[nautilus/wip/csoriano/flow: 535/537] icon-view: improve performance
- From: Carlos Soriano <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/flow: 535/537] icon-view: improve performance
- Date: Sun, 27 Nov 2016 16:30:44 +0000 (UTC)
commit 0f424b1e583332ba083b621d6b2bbcccd67cb514
Author: Carlos Soriano <csoriano gnome org>
Date: Thu May 12 18:09:07 2016 +0200
icon-view: improve performance
Add files in batch.
Some numbers:
canvas-view for 10.000 files: 0.02 s
icon-view: 22 s
icon-view with files in batch: 12 s
src/nautilus-files-view.c | 17 +++++++++++++++-
src/nautilus-files-view.h | 6 +++++
src/nautilus-icon-view.c | 46 ++++++++++++++++++++++++++++++++++++--------
3 files changed, 59 insertions(+), 10 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index fa44029..f95b7c1 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -131,10 +131,10 @@
#define MIN_COMMON_FILENAME_PREFIX_LENGTH 4
-
enum
{
ADD_FILE,
+ ADD_FILES,
BEGIN_FILE_CHANGES,
BEGIN_LOADING,
CLEAR,
@@ -3884,6 +3884,7 @@ process_old_files (NautilusFilesView *view)
GList *files_added, *files_changed, *node;
FileAndDirectory *pending;
GList *selection, *files;
+ g_autoptr (GList) pending_additions = NULL;
files_added = view->details->old_added_files;
files_changed = view->details->old_changed_files;
@@ -3907,6 +3908,12 @@ process_old_files (NautilusFilesView *view)
pending->file,
GUINT_TO_POINTER (TRUE));
}
+
+ if (files_added != NULL)
+ {
+ g_signal_emit (view,
+ signals[ADD_FILES], 0, pending_additions, pending->directory);
+ }
}
for (node = files_changed; node != NULL; node = node->next)
@@ -8930,6 +8937,14 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
+ signals[ADD_FILES] =
+ g_signal_new ("add-files",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, add_files),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2, G_TYPE_POINTER, NAUTILUS_TYPE_DIRECTORY);
signals[BEGIN_FILE_CHANGES] =
g_signal_new ("begin-file-changes",
G_TYPE_FROM_CLASS (klass),
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 70dcb2d..e465afb 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -80,6 +80,12 @@ struct NautilusFilesViewClass {
void (* add_file) (NautilusFilesView *view,
NautilusFile *file,
NautilusDirectory *directory);
+ /* The 'add_files' signal is emitted to add a set of files to the view.
+ * It must be replaced by each subclass.
+ */
+ void (* add_files) (NautilusFilesView *view,
+ GList *files,
+ NautilusDirectory *directory);
void (* remove_file) (NautilusFilesView *view,
NautilusFile *file,
NautilusDirectory *directory);
diff --git a/src/nautilus-icon-view.c b/src/nautilus-icon-view.c
index 35255bd..3a201df 100644
--- a/src/nautilus-icon-view.c
+++ b/src/nautilus-icon-view.c
@@ -165,7 +165,7 @@ real_zoom_to_level (NautilusFilesView *self,
}
static void
-real_restore_default_zoom_level (NautilusFilesView *self)
+real_restore_standard_zoom_level (NautilusFilesView *self)
{
}
@@ -233,17 +233,45 @@ real_sort_directories_first_changed (NautilusFilesView *self)
{
}
+static gpointer*
+convert_glist_to_array (GList *list)
+{
+ gpointer *array;
+ GList *l;
+ int i = 0;
+
+ g_return_val_if_fail (list != NULL, NULL);
+
+ array = g_malloc (g_list_length (list) * sizeof (list->data));
+
+ for (l = list; l != NULL; l = l->next, i++)
+ {
+ array[i] = l->data;
+ }
+
+ return array;
+}
+
static void
-real_add_file (NautilusFilesView *self,
- NautilusFile *file,
- NautilusDirectory *directory)
+real_add_files (NautilusFilesView *self,
+ GList *files,
+ NautilusDirectory *directory)
{
NautilusIconViewPrivate *priv;
+ g_autofree gpointer *array = NULL;
priv = nautilus_icon_view_get_instance_private (self);
- g_print ("add file %d\n", g_list_model_get_n_items (priv->model));
- g_list_store_append (G_LIST_STORE (priv->model), file);
+ clock_t start = clock() ;
+
+ g_print ("add file %d\n", g_list_length (files));
+ array = convert_glist_to_array (files);
+ g_list_store_splice (G_LIST_STORE (priv->model),
+ g_list_model_get_n_items (priv->model),
+ 0, array, g_list_length (files));
+ clock_t end = clock() ;
+ double elapsed_time = (end-start)/(double)CLOCKS_PER_SEC ;
+ g_print ("add file finished %d %f\n", g_list_model_get_n_items (priv->model), elapsed_time);
}
@@ -253,7 +281,7 @@ real_get_view_id (NautilusFilesView *self)
return NAUTILUS_VIEW_GRID_ID;
}
-static guint
+static GIcon*
real_get_icon (NautilusFilesView *self)
{
NautilusIconViewPrivate *priv;
@@ -433,7 +461,7 @@ nautilus_icon_view_class_init (NautilusIconViewClass *klass)
object_class->finalize = nautilus_icon_view_finalize;
- files_view_class->add_file = real_add_file;
+ files_view_class->add_files = real_add_files;
files_view_class->begin_loading = real_begin_loading;
files_view_class->bump_zoom_level = real_bump_zoom_level;
files_view_class->can_zoom_in = real_can_zoom_in;
@@ -446,7 +474,6 @@ nautilus_icon_view_class_init (NautilusIconViewClass *klass)
files_view_class->is_empty = real_is_empty;
files_view_class->remove_file = real_remove_file;
files_view_class->update_actions_state = real_update_actions_state;
- files_view_class->restore_default_zoom_level = real_restore_default_zoom_level;
files_view_class->reveal_selection = real_reveal_selection;
files_view_class->select_all = real_select_all;
files_view_class->set_selection = real_set_selection;
@@ -460,6 +487,7 @@ nautilus_icon_view_class_init (NautilusIconViewClass *klass)
files_view_class->scroll_to_file = real_scroll_to_file;
files_view_class->get_icon = real_get_icon;
files_view_class->select_first = real_select_first;
+ files_view_class->restore_standard_zoom_level = real_restore_standard_zoom_level;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]