Hash :
7f01591a
Author :
Date :
2006-11-12T17:35:38
Make fts (in FTS_CWDFD mode) more efficient by caching a few open
file descriptors. This also averts a failure on systems with
native openat support when a traversed directory lacks "x" access.
* lib/fts_.h: Include "i-ring.h"
(struct FTS) [fts_fd_ring]: New member.
* lib/fts.c (RESTORE_INITIAL_CWD): Also call fd_ring_clear.
(FCHDIR): Add parentheses.
(fd_ring_check, fd_ring_print) [!FTS_DEBUG]: Define away.
(cwd_advance_fd): Add a 3rd parameter. Adjust all callers.
When descending, rather than simply closing the previous
fts_cwd_fd value, push that file descriptor onto the ring.
(same_fd, fd_ring_print, fd_ring_check) [FTS_DEBUG]: New functions.
(fts_open): Initialize the new fd_ring member.
(fts_close): Clear the ring.
(fts_safe_changedir): When possible, use our new fd_ring to skip
the diropen and fstat and dev/ino comparison that would normally
accompany a virtual `chdir ("..")'.
* modules/fts (Depends-on): Add i-ring.
* modules/i-ring: New module.
* lib/i-ring.c, lib/i-ring.h, lib/i-ring-test.c: New files.
* m4/i-ring.m4: New file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <assert.h>
#include "i-ring.h"
/* Test with this:
gcc -I. -Wall -W -O i-ring-test.c i-ring.c -L. -lcoreutils && ./a.out
*/
int
main ()
{
I_ring ir;
i_ring_init (&ir, -1);
int o = i_ring_push (&ir, 1);
assert (o == -1);
o = i_ring_push (&ir, 2);
assert (o == -1);
o = i_ring_push (&ir, 3);
assert (o == -1);
o = i_ring_push (&ir, 4);
assert (o == -1);
o = i_ring_push (&ir, 5);
assert (o == 1);
o = i_ring_push (&ir, 6);
assert (o == 2);
o = i_ring_push (&ir, 7);
assert (o == 3);
o = i_ring_pop (&ir);
assert (o == 7);
o = i_ring_pop (&ir);
assert (o == 6);
o = i_ring_pop (&ir);
assert (o == 5);
o = i_ring_pop (&ir);
assert (o == 4);
assert (i_ring_empty (&ir));
o = i_ring_push (&ir, 8);
assert (o == -1);
o = i_ring_pop (&ir);
assert (o == 8);
assert (i_ring_empty (&ir));
return 0;
}