1
1

* dir.c (do_reload_dir): Optimize the logic - count the marks

and only match new entries against old entries if at least one
mark has not been transferred.
From Bjrn Eriksson <mdeans@algonet.se>
Этот коммит содержится в:
Pavel Roskin 2001-12-03 21:39:41 +00:00
родитель 72421061d3
Коммит 111c11418a
2 изменённых файлов: 69 добавлений и 48 удалений

Просмотреть файл

@ -1,3 +1,10 @@
2001-12-03 Pavel Roskin <proski@gnu.org>
* dir.c (do_reload_dir): Optimize the logic - count the marks
and only match new entries against old entries if at least one
mark has not been transferred.
From BjЎrn Eriksson <mdeans@algonet.se>
2001-11-29 Pavel Roskin <proski@gnu.org> 2001-11-29 Pavel Roskin <proski@gnu.org>
* main.c (midnight_callback): Implement "auto menus". * main.c (midnight_callback): Implement "auto menus".

Просмотреть файл

@ -83,8 +83,7 @@ typedef enum {
STRCOLL_TEST STRCOLL_TEST
} strcoll_status; } strcoll_status;
static int static int string_sortcomp (char *str1, char *str2)
string_sortcomp (char *str1, char *str2)
{ {
static strcoll_status use_strcoll = STRCOLL_TEST; static strcoll_status use_strcoll = STRCOLL_TEST;
@ -600,10 +599,11 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
int next_free = 0; int next_free = 0;
int i, found, status, link_to_dir, stalled_link; int i, status, link_to_dir, stalled_link;
struct stat buf; struct stat buf;
int tmp_len; /* For optimisation */ int tmp_len; /* For optimisation */
int dotdot_found = 0; int dotdot_found = 0;
int marked_cnt;
tree_store_start_check_cwd (); tree_store_start_check_cwd ();
dirp = mc_opendir ("."); dirp = mc_opendir (".");
@ -614,17 +614,21 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
} }
alloc_dir_copy (list->size); alloc_dir_copy (list->size);
for (i = 0; i < count; i++){ for (marked_cnt = i = 0; i < count; i++) {
dir_copy.list[i].fnamelen = list->list[i].fnamelen; dir_copy.list[i].fnamelen = list->list[i].fnamelen;
dir_copy.list[i].fname = list->list[i].fname; dir_copy.list[i].fname = list->list[i].fname;
dir_copy.list[i].f.marked = list->list[i].f.marked; dir_copy.list[i].f.marked = list->list[i].f.marked;
dir_copy.list [i].f.dir_size_computed = list->list [i].f.dir_size_computed; dir_copy.list[i].f.dir_size_computed =
list->list[i].f.dir_size_computed;
dir_copy.list[i].f.link_to_dir = list->list[i].f.link_to_dir; dir_copy.list[i].f.link_to_dir = list->list[i].f.link_to_dir;
dir_copy.list[i].f.stalled_link = list->list[i].f.stalled_link; dir_copy.list[i].f.stalled_link = list->list[i].f.stalled_link;
if (list->list[i].f.marked)
marked_cnt++;
} }
for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) { for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) {
status = handle_dirent (list, filter, dp, &buf, next_free, &link_to_dir, status =
handle_dirent (list, filter, dp, &buf, next_free, &link_to_dir,
&stalled_link); &stalled_link);
if (status == 0) if (status == 0)
continue; continue;
@ -644,17 +648,28 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
return next_free; return next_free;
} }
list->list[next_free].f.marked = 0;
tmp_len = NLENGTH (dp); tmp_len = NLENGTH (dp);
for (found = i = 0; i < count; i++)
/*
* If we have marked files in the copy, scan through the copy
* to find matching file. Decrease number of remaining marks if
* we copied one.
* TODO: Use binary search.
*/
if (marked_cnt > 0) {
for (i = 0; i < count; i++) {
if (tmp_len == dir_copy.list[i].fnamelen if (tmp_len == dir_copy.list[i].fnamelen
&& !strcmp (dp->d_name, dir_copy.list[i].fname)) { && !strcmp (dp->d_name, dir_copy.list[i].fname)) {
list->list [next_free].f.marked = dir_copy.list [i].f.marked; list->list[next_free].f.marked =
found = 1; dir_copy.list[i].f.marked;
if (dir_copy.list[i].f.marked) {
marked_cnt--;
}
break; break;
} }
}
if (!found) }
list->list [next_free].f.marked = 0;
list->list[next_free].fnamelen = tmp_len; list->list[next_free].fnamelen = tmp_len;
list->list[next_free].fname = g_strdup (dp->d_name); list->list[next_free].fname = g_strdup (dp->d_name);
@ -674,8 +689,7 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
if (!dotdot_found) if (!dotdot_found)
add_dotdot_to_list (list, next_free++); add_dotdot_to_list (list, next_free++);
do_sort (list, sort, next_free - 1, rev, case_sensitive); do_sort (list, sort, next_free - 1, rev, case_sensitive);
} } else
else
next_free = set_zero_dir (list); next_free = set_zero_dir (list);
clean_dir (&dir_copy, count); clean_dir (&dir_copy, count);
return next_free; return next_free;