Currently each call to telldir() requires a malloc and adds an entry to a
linked list which must be traversed on future telldir(), seekdir(),
closedir(), and readdir() calls. Applications that call telldir() for every
directory entry incur O(n^2) behavior in readdir() and O(n) in telldir() and
This optimization eliminates the malloc() and linked list in most cases by
packing the relevant information into a single long. On 64-bit
architectures, msdosfs, NFS, tmpfs, UFS, and ZFS can all use the packed
representation. Memory savings is about 50 bytes per telldir(3) call.
Speedup for telldir()-heavy directory traversals is about 20-30x for one
million files per directory.
An outstanding question is how to handle directories with > 2^31 files on
32-bit architectures. The current implementation breaks telldir() for such