Tune fts for FTS_LOGICAL+FTS_NOSTAT
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 25 Apr 2020 18:02:53 +0000 (11:02 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 25 Apr 2020 18:05:07 +0000 (11:05 -0700)
From a suggestion by Askar Safin in:
https://lists.gnu.org/r/bug-gnulib/2020-04/msg00074.html
* lib/fts.c (fts_build): If file types are known, optimize
FTS_LOGICAL+FTS_NOSTAT for non-symlinks and non-directories the
same way that we already optimize FTS_PHYSICAL+FTS_NOSTAT for
non-directories.

ChangeLog
lib/fts.c

index 4bf912fe4b3c6e7d9435c99c4f5b872033267ce6..c13c82bacb84d00ec3feaee0e92444e790e72564 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-04-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Tune fts for FTS_LOGICAL+FTS_NOSTAT
+       From a suggestion by Askar Safin in:
+       https://lists.gnu.org/r/bug-gnulib/2020-04/msg00074.html
+       * lib/fts.c (fts_build): If file types are known, optimize
+       FTS_LOGICAL+FTS_NOSTAT for non-symlinks and non-directories the
+       same way that we already optimize FTS_PHYSICAL+FTS_NOSTAT for
+       non-directories.
+
 2020-04-19  Bruno Haible  <bruno@clisp.org>
 
        vasnprintf: Add support for printing wide characters using escapes.
index ade8c3349175a42bf486e2193a529d4f30d2ab5c..bf62dfa92625cffbcf1a3bf3cb28d6b5723cc1fc 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1511,10 +1511,11 @@ mem1:                           saved_errno = errno;
                            inode numbers.  Some day we might optimize that
                            away, too, for directories where d_ino is known to
                            be valid.  */
-                        bool skip_stat = (ISSET(FTS_PHYSICAL)
-                                          && ISSET(FTS_NOSTAT)
+                        bool skip_stat = (ISSET(FTS_NOSTAT)
                                           && DT_IS_KNOWN(dp)
-                                          && ! DT_MUST_BE(dp, DT_DIR));
+                                          && ! DT_MUST_BE(dp, DT_DIR)
+                                          && (ISSET(FTS_PHYSICAL)
+                                              || ! DT_MUST_BE(dp, DT_LNK)));
                         p->fts_info = FTS_NSOK;
                         /* Propagate dirent.d_type information back
                            to caller, when possible.  */