fts: arrange not to stat non-directories in more cases
authorJim Meyering <meyering@redhat.com>
Wed, 11 Feb 2009 20:32:01 +0000 (21:32 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 13 Feb 2009 10:39:56 +0000 (11:39 +0100)
commit97d5b66578be50712cb77fbe6a047b8fffa1cfbd
tree250e9b228aacf472a56092fc9c35562dbc4aa0be
parent4cfd2434f2c5ec5d85993825ed888473612b4a2f
fts: arrange not to stat non-directories in more cases

This makes GNU find (when it doesn't need to stat each file)
*much* more efficient at traversing reiserfs file systems.

* lib/fts_.h (struct ftsent) [fts_n_dirs_remaining]: New member.
(struct FTS) [fts_leaf_optimization_works_ht]: Add member.
* lib/fts.c (fts_close): Free ->fts_leaf_optimization_works_ht.
(S_MAGIC_REISERFS, S_MAGIC_PROC): Define.
(leaf_optimization_applies): New function.
(LCO_hash, LCO_compare): New helper functions.
(link_count_optimize_ok): New function.
(fts_stat): Initialize new member (if dir).
(fts_read): Decrement parent's fts_n_dirs_remaining count if
we've just stat'ed a directory.  Skip the stat call when possible.

Note this AFS-related exchange:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=143111
and note find's pioctl call in find/fstype.c.
But that is necessary only if you want to enable the
optimization for AFS, and for now, I don't.
ChangeLog
lib/fts.c
lib/fts_.h