diff --git a/ChangeLog b/ChangeLog index 41c2d3d8202fc6b189115c650d113cb7660a29ae..c85d0c76feb524cf6f4e5961d3e9ee31047b2bdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-09-02 Benedikt Meurer <benny@xfce.org> + + * thunar/thunar-standard-view.c: Avoid going through the selection + changed handling whenever the number of files in a model changes, + as the only thing that needs updating here is the statusbar text. + * thunar-vfs/thunar-vfs-mime-cache.c + (thunar_vfs_mime_cache_lookup_parents): Fix the offset from which the + parent mime type name is read. + * thunar-vfs/thunar-vfs-mime-cache.c(cache_node_lookup_suffix): + Optimize the tail-recursive suffix lookup. + * thunar-vfs/thunar-vfs-mime-database.c + (thunar_vfs_mime_database_get_info_for_file): Use fast stack memory + for the extattr and content lookups. + 2005-09-02 Benedikt Meurer <benny@xfce.org> * thunar/thunar-icon-factory.c(thunar_icon_factory_lookup_icon): Add diff --git a/thunar-vfs/thunar-vfs-mime-cache.c b/thunar-vfs/thunar-vfs-mime-cache.c index 04dcc833f38c7bd8a774533f4574fd7e056d7161..5f64db3a3885c2a331f9f6d87e89970f28770ccd 100644 --- a/thunar-vfs/thunar-vfs-mime-cache.c +++ b/thunar-vfs/thunar-vfs-mime-cache.c @@ -331,6 +331,7 @@ cache_node_lookup_suffix (const gchar *buffer, gunichar match_char; gint min, max, mid; +next: character = g_utf8_get_char (suffix); if (ignore_case) character = g_unichar_tolower (character); @@ -354,9 +355,20 @@ cache_node_lookup_suffix (const gchar *buffer, } else { - return cache_node_lookup_suffix (buffer, CACHE_READ32 (buffer, offset + 16 * mid + 8), - CACHE_READ32 (buffer, offset + 16 * mid + 12), - suffix, ignore_case); + /* We emulate a recursive call to cache_node_lookup_suffix() + * here. This optimization works because the algorithm is + * tail-recursive. The goto is not necessarily nice, but it + * works for our purpose and doesn't decrease readability. + * If we'd use a recursive call here, the code would look + * like this: + * + * return cache_node_lookup_suffix (buffer, CACHE_READ32 (buffer, offset + 16 * mid + 8), + * CACHE_READ32 (buffer, offset + 16 * mid + 12), + * suffix, ignore_case); + */ + n_entries = CACHE_READ32 (buffer, offset + 16 * mid + 8); + offset = CACHE_READ32 (buffer, offset + 16 * mid + 12); + goto next; } } } @@ -450,7 +462,7 @@ thunar_vfs_mime_cache_lookup_parents (ThunarVfsMimeProvider *provider, n_parents = CACHE_READ32 (buffer, parents_offset); for (l = 0; l < n_parents && j < max_parents; ++l, ++j) - parents[j] = (gchar *) (buffer + parents_offset + 4 + 4 * l); + parents[j] = (gchar *) (buffer + CACHE_READ32 (buffer, parents_offset + 4 + 4 * l)); } return j; diff --git a/thunar-vfs/thunar-vfs-mime-database.c b/thunar-vfs/thunar-vfs-mime-database.c index 7651a48e642cbd42e44e8f8d9c1bbd0eb64dfdef..e349cdb704177a321e5948de8c972f10d97f12fd 100644 --- a/thunar-vfs/thunar-vfs-mime-database.c +++ b/thunar-vfs/thunar-vfs-mime-database.c @@ -997,14 +997,13 @@ thunar_vfs_mime_database_get_info_for_file (ThunarVfsMimeDatabase *database, { if (fstat (fd, &stat) == 0) { - buffer = g_new (gchar, stat.st_size + 1); + buffer = g_newa (gchar, stat.st_size + 1); nbytes = read (fd, buffer, stat.st_size); if (G_LIKELY (nbytes >= 3)) { buffer[nbytes] = '\0'; info = thunar_vfs_mime_database_get_info (database, buffer); } - g_free (buffer); } close (fd); } @@ -1022,28 +1021,26 @@ thunar_vfs_mime_database_get_info_for_file (ThunarVfsMimeDatabase *database, nbytes = extattr_get_fd (fd, EXTATTR_NAMESPACE_USER, "mime_type", NULL, 0); if (G_UNLIKELY (nbytes >= 3)) { - buffer = g_new (gchar, nbytes + 1); + buffer = g_newa (gchar, nbytes + 1); nbytes = extattr_get_fd (fd, EXTATTR_NAMESPACE_USER, "mime_type", buffer, nbytes); if (G_LIKELY (nbytes >= 3)) { buffer[nbytes] = '\0'; info = thunar_vfs_mime_database_get_info (database, buffer); } - g_free (buffer); } #elif defined(HAVE_FGETXATTR) /* check for valid mime type stored in the extattr (Linux) */ nbytes = fgetxattr (fd, "user.mime_type", NULL, 0); if (G_UNLIKELY (nbytes >= 3)) { - buffer = g_new (gchar, nbytes + 1); + buffer = g_newa (gchar, nbytes + 1); nbytes = fgetxattr (fd, "user.mime_type", buffer, nbytes); if (G_LIKELY (nbytes >= 3)) { buffer[nbytes] = '\0'; info = thunar_vfs_mime_database_get_info (database, buffer); } - g_free (buffer); } #endif @@ -1052,7 +1049,7 @@ thunar_vfs_mime_database_get_info_for_file (ThunarVfsMimeDatabase *database, { /* read the beginning from the file */ buflen = MIN (stat.st_size, database->max_buffer_extents); - buffer = g_new (gchar, buflen); + buffer = g_newa (gchar, buflen); nbytes = read (fd, buffer, buflen); /* try to determine a type from the buffer contents */ @@ -1072,9 +1069,6 @@ thunar_vfs_mime_database_get_info_for_file (ThunarVfsMimeDatabase *database, g_mutex_unlock (database->lock); } - - /* cleanup */ - g_free (buffer); } /* cleanup */ diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index f21fad01d31e72e55db37b08735f4086ffd09e45..bb553be2d1f3cc072cf9f7b7b84884b1350e5b8c 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -118,6 +118,9 @@ static void thunar_standard_view_action_rename (GtkAction ThunarStandardView *standard_view); static void thunar_standard_view_action_show_hidden_files (GtkToggleAction *toggle_action, ThunarStandardView *standard_view); +static void thunar_standard_view_notify_num_files (ThunarListModel *model, + GParamSpec *pspec, + ThunarStandardView *standard_view); static gboolean thunar_standard_view_button_release_event (GtkWidget *view, GdkEventButton *event, ThunarStandardView *standard_view); @@ -406,8 +409,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view) /* be sure to update the statusbar text whenever the number of * files in our model changes. */ - g_signal_connect_swapped (G_OBJECT (standard_view->model), "notify::num-files", - G_CALLBACK (thunar_standard_view_selection_changed), standard_view); + g_signal_connect (G_OBJECT (standard_view->model), "notify::num-files", G_CALLBACK (thunar_standard_view_notify_num_files), standard_view); /* allocate the launcher support */ standard_view->priv->launcher = thunar_launcher_new (); @@ -1255,6 +1257,24 @@ thunar_standard_view_action_show_hidden_files (GtkToggleAction *toggle_action +static void +thunar_standard_view_notify_num_files (ThunarListModel *model, + GParamSpec *pspec, + ThunarStandardView *standard_view) +{ + g_return_if_fail (THUNAR_IS_LIST_MODEL (model)); + g_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); + + /* clear the current status text (will be recalculated on-demand) */ + g_free (standard_view->statusbar_text); + standard_view->statusbar_text = NULL; + + /* tell everybody that the statusbar text may have changed */ + g_object_notify (G_OBJECT (standard_view), "statusbar-text"); +} + + + static gboolean thunar_standard_view_button_release_event (GtkWidget *view, GdkEventButton *event,