Performance patch, dir.c:do_reload_dir() on large dirs.

Björn Eriksson mdeans at algonet.se
Thu Nov 29 17:56:53 UTC 2001


 I had some problems with /tmp/ksocket/* when it contained ~20'000
files, all of the same length thus foiling the strlen() 'optimisation'.

 This small patch tries to skip the check-if-file-was-marked-in-the-
old-list-logic if no files we're marked at all. It considered
decrementing 'marked_cnt' for every found file but I think do_load_dir()
and do_reload_dir() would be better off with a hash table.

 BTW: lxr on gnome is:

  1) not linked from the project page and
  2) not working, try src/dir.c

 Inline against yesterdays snapshot (2001-11-28):

--- dir.c-org	Wed Nov 28 17:18:55 2001
+++ dir.c	Wed Nov 28 17:37:27 2001
@@ -600,10 +600,11 @@ do_reload_dir (dir_list *list, sortfn *s
     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,13 +615,15 @@ do_reload_dir (dir_list *list, sortfn *s
     }
 
     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.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)){
@@ -644,17 +647,17 @@ do_reload_dir (dir_list *list, sortfn *s
 	    return next_free;
 	}
 
+	list->list [next_free].f.marked = 0;
 	tmp_len = NLENGTH (dp);
-	for (found = i = 0; i < count; i++)
+	if ( marked_cnt ) {
+	    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;
 		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);


-- 
//Björnen, my 'd' key is flimsy :(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc/attachments/20011129/de392571/attachment.asc>


More information about the mc mailing list