Speed up walkDir significantly

We only know that this works on Linux and Mac OS X, so other systems use
the POSIX conforming version still. This removed the lstat call, which
is especially expensive on NFS filesystems for me.
This commit is contained in:
def 2015-02-24 16:37:54 +01:00
commit 1adebdc767
2 changed files with 20 additions and 3 deletions

View file

@ -1299,10 +1299,14 @@ iterator walkDir*(dir: string): tuple[kind: PathComponent, path: string] {.
if y != "." and y != "..":
var s: TStat
y = dir / y
if lstat(y, s) < 0'i32: break
var k = pcFile
if S_ISDIR(s.st_mode): k = pcDir
if S_ISLNK(s.st_mode): k = succ(k)
when defined(linux) or defined(macosx):
if x.d_type == DT_DIR: k = pcDir
if x.d_type == DT_LNK: k = succ(k)
else:
if lstat(y, s) < 0'i32: break
if S_ISDIR(s.st_mode): k = pcDir
if S_ISLNK(s.st_mode): k = succ(k)
yield (k, y)
discard closedir(d)