Skip to content
Snippets Groups Projects
Commit a2506b8a authored by Benedikt Meurer's avatar Benedikt Meurer
Browse files

2005-06-15 Benedikt Meurer <benny@xfce.org>

	* thunar/thunar-icon-factory.c: Implement the recently used list using
	  a circular buffer. This saves us from having to memmove() the list
	  content on every icon lookup.
	* thunar/thunar-window.c(thunar_window_set_current_directory): Use
	  a simple optimization when loading new folders into a view. See the
	  code comments for details about the trick.




(Old svn revision: 16336)
parent a62a6d77
No related branches found
No related tags found
No related merge requests found
2005-06-15 Benedikt Meurer <benny@xfce.org>
* thunar/thunar-icon-factory.c: Implement the recently used list using
a circular buffer. This saves us from having to memmove() the list
content on every icon lookup.
* thunar/thunar-window.c(thunar_window_set_current_directory): Use
a simple optimization when loading new folders into a view. See the
code comments for details about the trick.
2005-06-14 Benedikt Meurer <benny@xfce.org>
* configure.in.in: Depend on GLib 2.6 for now.
......
......@@ -106,8 +106,8 @@ struct _ThunarIconFactory
{
GObject __parent__;
GdkPixbuf *recently[MAX_RECENTLY];
guint n_recently;
GdkPixbuf *recently[MAX_RECENTLY]; /* ring buffer */
guint recently_pos; /* insert position */
GHashTable *icon_cache;
......@@ -236,8 +236,9 @@ thunar_icon_factory_finalize (GObject *object)
g_return_if_fail (THUNAR_IS_ICON_FACTORY (factory));
/* clear the recently used list */
for (n = 0; n < factory->n_recently; ++n)
g_object_unref (G_OBJECT (factory->recently[n]));
for (n = 0; n < MAX_RECENTLY; ++n)
if (G_LIKELY (factory->recently[n] != NULL))
g_object_unref (G_OBJECT (factory->recently[n]));
/* clear the icon cache hash table */
g_hash_table_destroy (factory->icon_cache);
......@@ -318,9 +319,12 @@ thunar_icon_factory_changed (GtkIconTheme *icon_theme,
guint n;
/* drop all items from the recently used list */
for (n = 0; n < factory->n_recently; ++n)
g_object_unref (G_OBJECT (factory->recently[n]));
factory->n_recently = 0;
for (n = 0; n < MAX_RECENTLY; ++n)
if (G_LIKELY (factory->recently[n] != NULL))
{
g_object_unref (G_OBJECT (factory->recently[n]));
factory->recently[n] = NULL;
}
/* drop all items from the icon cache */
g_hash_table_foreach_remove (factory->icon_cache, (GHRFunc)gtk_true, NULL);
......@@ -483,24 +487,22 @@ thunar_icon_factory_mark_recently_used (ThunarIconFactory *factory,
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
/* check if the icon is already on the list */
for (n = 0; n < factory->n_recently; ++n)
for (n = 0; n < MAX_RECENTLY; ++n)
if (G_UNLIKELY (factory->recently[n] == pixbuf))
return;
/* prepend it to the list of recently used icons */
if (factory->n_recently == MAX_RECENTLY)
{
/* drop the oldest icon from the recently used list */
g_object_unref (G_OBJECT (factory->recently[MAX_RECENTLY - 1]));
}
else
{
++factory->n_recently;
}
// FIXME: better use a ring-buffer than memmove()'ing all the time
memmove (factory->recently + 1, factory->recently, (factory->n_recently - 1) * sizeof (GdkPixbuf *));
/* ditch the previous item on the current insert position,
* which - if present - is the oldest item in the list.
*/
if (G_LIKELY (factory->recently[factory->recently_pos] != NULL))
g_object_unref (G_OBJECT (factory->recently[factory->recently_pos]));
/* insert the new pixbuf into the list */
factory->recently[factory->recently_pos] = pixbuf;
g_object_ref (G_OBJECT (pixbuf));
factory->recently[0] = pixbuf;
/* advance the insert position */
factory->recently_pos = (factory->recently_pos + 1) % MAX_RECENTLY;
/* schedule the sweeper */
if (factory->sweep_timer_id < 0)
......
......@@ -303,8 +303,17 @@ thunar_window_set_current_directory (ThunarWindow *window,
g_object_unref (G_OBJECT (icon));
}
/* setup the folder for the view */
/* setup the folder for the view, we use a simple but very effective
* trick here to speed up the folder change: we completely disconnect
* the model from the view, load the folder into the model and afterwards
* reconnect the model with the view. This way we avoid having to fire
* and process thousands of row_removed() and row_inserted() signals.
* Instead the view can process the complete file list in the model
* ONCE.
*/
model = thunar_view_get_list_model (THUNAR_VIEW (window->view));
g_object_ref (G_OBJECT (model));
thunar_view_set_list_model (THUNAR_VIEW (window->view), NULL);
if (G_LIKELY (current_directory != NULL))
{
/* try to open the directory */
......@@ -342,6 +351,8 @@ thunar_window_set_current_directory (ThunarWindow *window,
/* just reset the folder, so nothing is displayed */
thunar_list_model_set_folder (model, NULL);
}
thunar_view_set_list_model (THUNAR_VIEW (window->view), model);
g_object_unref (G_OBJECT (model));
/* tell everybody that we have a new "current-directory" */
g_object_notify (G_OBJECT (window), "current-directory");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment