mirror of https://github.com/MidnightCommander/mc
* 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>
This commit is contained in:
parent
72421061d3
commit
111c11418a
|
@ -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>
|
||||
|
||||
* main.c (midnight_callback): Implement "auto menus".
|
||||
|
|
42
src/dir.c
42
src/dir.c
|
@ -83,8 +83,7 @@ typedef enum {
|
|||
STRCOLL_TEST
|
||||
} strcoll_status;
|
||||
|
||||
static int
|
||||
string_sortcomp (char *str1, char *str2)
|
||||
static int string_sortcomp (char *str1, char *str2)
|
||||
{
|
||||
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;
|
||||
struct dirent *dp;
|
||||
int next_free = 0;
|
||||
int i, found, status, link_to_dir, stalled_link;
|
||||
int i, status, link_to_dir, stalled_link;
|
||||
struct stat buf;
|
||||
int tmp_len; /* For optimisation */
|
||||
int dotdot_found = 0;
|
||||
int marked_cnt;
|
||||
|
||||
tree_store_start_check_cwd ();
|
||||
dirp = mc_opendir (".");
|
||||
|
@ -614,17 +614,21 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
|
|||
}
|
||||
|
||||
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].fname = list->list[i].fname;
|
||||
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.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)) {
|
||||
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);
|
||||
if (status == 0)
|
||||
continue;
|
||||
|
@ -644,17 +648,28 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
|
|||
return next_free;
|
||||
}
|
||||
|
||||
list->list[next_free].f.marked = 0;
|
||||
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
|
||||
&& !strcmp (dp->d_name, dir_copy.list[i].fname)) {
|
||||
list->list [next_free].f.marked = dir_copy.list [i].f.marked;
|
||||
found = 1;
|
||||
list->list[next_free].f.marked =
|
||||
dir_copy.list[i].f.marked;
|
||||
if (dir_copy.list[i].f.marked) {
|
||||
marked_cnt--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
list->list [next_free].f.marked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
list->list[next_free].fnamelen = tmp_len;
|
||||
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)
|
||||
add_dotdot_to_list (list, next_free++);
|
||||
do_sort (list, sort, next_free - 1, rev, case_sensitive);
|
||||
}
|
||||
else
|
||||
} else
|
||||
next_free = set_zero_dir (list);
|
||||
clean_dir (&dir_copy, count);
|
||||
return next_free;
|
||||
|
|
Loading…
Reference in New Issue