* 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>
Этот коммит содержится в:
родитель
72421061d3
Коммит
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>
|
2001-11-29 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* main.c (midnight_callback): Implement "auto menus".
|
* main.c (midnight_callback): Implement "auto menus".
|
||||||
|
110
src/dir.c
110
src/dir.c
@ -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;
|
||||||
|
|
||||||
@ -594,75 +593,91 @@ alloc_dir_copy (int size)
|
|||||||
|
|
||||||
/* If filter is null, then it is a match */
|
/* If filter is null, then it is a match */
|
||||||
int
|
int
|
||||||
do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
|
do_reload_dir (dir_list * list, sortfn * sort, int count, int rev,
|
||||||
int case_sensitive, char *filter)
|
int case_sensitive, char *filter)
|
||||||
{
|
{
|
||||||
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 (".");
|
||||||
if (!dirp) {
|
if (!dirp) {
|
||||||
clean_dir (list, count);
|
clean_dir (list, count);
|
||||||
tree_store_end_check ();
|
tree_store_end_check ();
|
||||||
return set_zero_dir (list);
|
return set_zero_dir (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 =
|
||||||
dir_copy.list [i].f.link_to_dir = list->list [i].f.link_to_dir;
|
list->list[i].f.dir_size_computed;
|
||||||
dir_copy.list [i].f.stalled_link = list->list [i].f.stalled_link;
|
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)){
|
for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) {
|
||||||
status = handle_dirent (list, filter, dp, &buf, next_free, &link_to_dir,
|
status =
|
||||||
&stalled_link);
|
handle_dirent (list, filter, dp, &buf, next_free, &link_to_dir,
|
||||||
|
&stalled_link);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
continue;
|
continue;
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
mc_closedir (dirp);
|
mc_closedir (dirp);
|
||||||
/* Norbert (Feb 12, 1997):
|
/* Norbert (Feb 12, 1997):
|
||||||
Just in case someone finds this memory leak:
|
Just in case someone finds this memory leak:
|
||||||
-1 means big trouble (at the moment no memory left),
|
-1 means big trouble (at the moment no memory left),
|
||||||
I don't bother with further cleanup because if one gets to
|
I don't bother with further cleanup because if one gets to
|
||||||
this point he will have more problems than a few memory
|
this point he will have more problems than a few memory
|
||||||
leaks and because one 'clean_dir' would not be enough (and
|
leaks and because one 'clean_dir' would not be enough (and
|
||||||
because I don't want to spent the time to make it working,
|
because I don't want to spent the time to make it working,
|
||||||
IMHO it's not worthwhile).
|
IMHO it's not worthwhile).
|
||||||
clean_dir (&dir_copy, count);
|
clean_dir (&dir_copy, count);
|
||||||
*/
|
*/
|
||||||
tree_store_end_check ();
|
tree_store_end_check ();
|
||||||
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 (tmp_len == dir_copy.list [i].fnamelen
|
/*
|
||||||
&& !strcmp (dp->d_name, dir_copy.list [i].fname)){
|
* If we have marked files in the copy, scan through the copy
|
||||||
list->list [next_free].f.marked = dir_copy.list [i].f.marked;
|
* to find matching file. Decrease number of remaining marks if
|
||||||
found = 1;
|
* we copied one.
|
||||||
break;
|
* 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;
|
||||||
|
if (dir_copy.list[i].f.marked) {
|
||||||
|
marked_cnt--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!found)
|
list->list[next_free].fnamelen = tmp_len;
|
||||||
list->list [next_free].f.marked = 0;
|
list->list[next_free].fname = g_strdup (dp->d_name);
|
||||||
|
list->list[next_free].f.link_to_dir = link_to_dir;
|
||||||
list->list [next_free].fnamelen = tmp_len;
|
list->list[next_free].f.stalled_link = stalled_link;
|
||||||
list->list [next_free].fname = g_strdup (dp->d_name);
|
list->list[next_free].f.dir_size_computed = 0;
|
||||||
list->list [next_free].f.link_to_dir = link_to_dir;
|
list->list[next_free].buf = buf;
|
||||||
list->list [next_free].f.stalled_link = stalled_link;
|
if (strcmp (dp->d_name, "..") == 0)
|
||||||
list->list [next_free].f.dir_size_computed = 0;
|
|
||||||
list->list [next_free].buf = buf;
|
|
||||||
if (strcmp (dp->d_name, ".." ) == 0)
|
|
||||||
dotdot_found = 1;
|
dotdot_found = 1;
|
||||||
next_free++;
|
next_free++;
|
||||||
if (!(next_free % 16))
|
if (!(next_free % 16))
|
||||||
@ -673,9 +688,8 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
|
|||||||
if (next_free) {
|
if (next_free) {
|
||||||
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;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user