Skip to content

Commit 845feec

Browse files
authored
Merge pull request #2193 from bdash/avoid-double-stat
Avoid unnecessary calls to stat within NSURLDirectoryEnumerator
2 parents 778e6d3 + f22aeb2 commit 845feec

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Foundation/FileManager+POSIX.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ extension FileManager {
693693
let ps = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 2)
694694
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
695695
ps.advanced(by: 1).initialize(to: nil)
696-
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
696+
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil)
697697
ps.deinitialize(count: 2)
698698
ps.deallocate()
699699

@@ -1050,7 +1050,7 @@ internal func _contentsEqual(atPath path1: String, andPath path2: String) -> Boo
10501050
defer { ps.deallocate() }
10511051
ps.initialize(to: UnsafeMutablePointer(mutating: fsRep))
10521052
ps.advanced(by: 1).initialize(to: nil)
1053-
return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
1053+
return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil)
10541054
}
10551055
if _stream == nil {
10561056
throw _NSErrorWithErrno(errno, reading: true, url: url)
@@ -1106,13 +1106,13 @@ internal func _contentsEqual(atPath path1: String, andPath path2: String) -> Boo
11061106
fts_set(_stream, _current, FTS_SKIP)
11071107
}
11081108
if showFile {
1109-
return URL(fileURLWithPath: filename)
1109+
return URL(fileURLWithPath: filename, isDirectory: true)
11101110
}
11111111

11121112
case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE:
11131113
let (showFile, _) = match(filename: filename, to: _options, isDir: false)
11141114
if showFile {
1115-
return URL(fileURLWithPath: filename)
1115+
return URL(fileURLWithPath: filename, isDirectory: false)
11161116
}
11171117
case FTS_DNR, FTS_ERR, FTS_NS:
11181118
let keepGoing: Bool

0 commit comments

Comments
 (0)