Skip to content

Commit f22aeb2

Browse files
committed
Pass FTS_NOSTAT to fts_open within _removeItem and NSURLDirectoryEnumerator
The FTS_NOSTAT flag indicates to fts_read that the caller is not interested in the fts_statp field of the FTSENT structure, allowing fts_read to skip calling stat in some circumstances. This reduces the runtime of FileManager.enumerator(at:includingPropertiesForKeys:options:errorHandler:) by a further 25%.
1 parent 830d55b commit f22aeb2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Foundation/FileManager+POSIX.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ extension FileManager {
686686
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 2)
687687
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
688688
ps.advanced(by: 1).initialize(to: nil)
689-
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
689+
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil)
690690
ps.deinitialize(count: 2)
691691
ps.deallocate()
692692

@@ -1043,7 +1043,7 @@ internal func _contentsEqual(atPath path1: String, andPath path2: String) -> Boo
10431043
defer { ps.deallocate() }
10441044
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
10451045
ps.advanced(by: 1).initialize(to: nil)
1046-
return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
1046+
return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil)
10471047
}
10481048
if _stream == nil {
10491049
throw _NSErrorWithErrno(errno, reading: true, url: url)

0 commit comments

Comments
 (0)