From c31e413b2a92ceab55c01e1f5351e6d485ea54ca Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 10 Sep 2014 10:19:25 +0400 Subject: [PATCH] Reduce update rate in the "Directory scanning" dialog. As a result, directory scannig is faster than before. The author of idea and initial patch is Egmont Koblinger. Signed-off-by: Andrew Borodin --- src/filemanager/cmd.c | 4 ++-- src/filemanager/file.c | 37 +++++++++++++------------------------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 84984896b..df98e2f60 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -1515,7 +1515,7 @@ single_dirsize_cmd (void) p = vfs_path_from_str (entry->fname); memset (&dsm, 0, sizeof (dsm)); - status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 1.0, dirsize_status_init_cb, + status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb, dirsize_status_update_cb, dirsize_status_deinit_cb); if (compute_dir_size (p, &dsm, &dir_count, &count, &total, TRUE) == FILE_CONT) @@ -1550,7 +1550,7 @@ dirsizes_cmd (void) dirsize_status_msg_t dsm; memset (&dsm, 0, sizeof (dsm)); - status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 1.0, dirsize_status_init_cb, + status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb, dirsize_status_update_cb, dirsize_status_deinit_cb); for (i = 0; i < panel->dir.len; i++) diff --git a/src/filemanager/file.c b/src/filemanager/file.c index caf375b37..9fbf08154 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -521,7 +521,9 @@ do_compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * ds size_t * dir_count, size_t * ret_marked, uintmax_t * ret_total, gboolean compute_symlinks) { - static unsigned short int update_ui_count = 0; + static guint64 timestamp = 0; + /* update with 25 FPS rate */ + static const guint64 delay = G_USEC_PER_SEC / 25; status_msg_t *sm = STATUS_MSG (dsm); int res; @@ -564,36 +566,23 @@ do_compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * ds if (res == 0) { if (S_ISDIR (s.st_mode)) - { ret = do_compute_dir_size (tmp_vpath, dsm, dir_count, ret_marked, ret_total, compute_symlinks); - if (ret == FILE_CONT && sm->update != NULL) - { - dsm->dirname_vpath = tmp_vpath; - dsm->dir_count = *dir_count; - dsm->total_size = *ret_total; - ret = (FileProgressStatus) sm->update (sm); - } - } else { + ret = FILE_CONT; + (*ret_marked)++; *ret_total += (uintmax_t) s.st_size; + } - update_ui_count++; - if ((update_ui_count & 31) == 0) - { - if (sm->update == NULL) - ret = FILE_CONT; - else - { - dsm->dirname_vpath = dirname_vpath; - dsm->dir_count = *dir_count; - dsm->total_size = *ret_total; - ret = (FileProgressStatus) sm->update (sm); - } - } + if (ret == FILE_CONT && sm->update != NULL && mc_time_elapsed (×tamp, delay)) + { + dsm->dirname_vpath = tmp_vpath; + dsm->dir_count = *dir_count; + dsm->total_size = *ret_total; + ret = (FileProgressStatus) sm->update (sm); } } @@ -1341,7 +1330,7 @@ panel_operate_init_totals (const WPanel * panel, const char *source, file_op_con memset (&dsm, 0, sizeof (dsm)); dsm.allow_skip = TRUE; - status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 1.0, dirsize_status_init_cb, + status_msg_init (STATUS_MSG (&dsm), _("Directory scanning"), 0, dirsize_status_init_cb, dirsize_status_update_cb, dirsize_status_deinit_cb); ctx->progress_count = 0;