changeset 30252:074c2db80df8

fts.c: adjust a new interface to be more generally useful * lib/fts.c (dirent_inode_sort_may_be_useful): Take an FD parameter. (fts_build): Adjust caller.
author Jim Meyering <meyering@redhat.com>
date Wed, 01 Oct 2008 09:22:11 +0200
parents 92f2f30a1b6d
children 19dddf05ec2a
files ChangeLog lib/fts.c
diffstat 2 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Oct 01 03:39:40 2008 +0200
+++ b/ChangeLog	Wed Oct 01 09:22:11 2008 +0200
@@ -1,3 +1,9 @@
+2008-10-01  Jim Meyering  <meyering@redhat.com>
+
+	fts.c: adjust a new interface to be more generally useful
+	* lib/fts.c (dirent_inode_sort_may_be_useful): Take an FD parameter.
+	(fts_build): Adjust caller.
+
 2008-09-30  Yoann Vandoorselaere  <yoann.v@prelude-ids.com>
 
 	* modules/cond-tests: New file.
--- a/lib/fts.c	Wed Oct 01 03:39:40 2008 +0200
+++ b/lib/fts.c	Wed Oct 01 09:22:11 2008 +0200
@@ -955,18 +955,19 @@
 }
 
 /* Return true if it is easy to determine the file system type of the
-   current directory, and sorting dirents on inode numbers is known to
-   improve traversal performance with that type of file system.  */
+   directory on which DIR_FD is open, and sorting dirents on inode numbers
+   is known to improve traversal performance with that type of file system.  */
 static bool
-dirent_inode_sort_may_be_useful (FTS const *sp)
+dirent_inode_sort_may_be_useful (int dir_fd)
 {
+  /* Skip the sort only if we can determine efficiently
+     that skipping it is the right thing to do.
+     The cost of performing an unnecessary sort is negligible,
+     while the cost of *not* performing it can be O(N^2) with
+     a very large constant.  */
   struct statfs fs_buf;
-  /* Skip the sort only if we can determine efficiently
-     that it's the right thing to do.  */
-  bool skip = (ISSET (FTS_CWDFD)
-	       && fstatfs (sp->fts_cwd_fd, &fs_buf) == 0
-	       && fs_handles_readdir_ordered_dirents_efficiently
-	            (fs_buf.f_type));
+  bool skip = (fstatfs (dir_fd, &fs_buf) == 0
+	       && fs_handles_readdir_ordered_dirents_efficiently (dir_fd));
   return !skip;
 }
 #else
@@ -1289,7 +1290,8 @@
 	   inode numbers.  */
 	if (nitems > _FTS_INODE_SORT_DIR_ENTRIES_THRESHOLD
 	    && !sp->fts_compar
-	    && dirent_inode_sort_may_be_useful (sp)) {
+	    && ISSET (FTS_CWDFD)
+	    && dirent_inode_sort_may_be_useful (sp->fts_cwd_fd)) {
 		sp->fts_compar = fts_compare_ino;
 		head = fts_sort (sp, head, nitems);
 		sp->fts_compar = NULL;