Skip to content

Commit ae04b6e

Browse files
authored
Speedup to detect the existence of files on Windows (#4977)
On Windows, `Filesystem::exists` forward the call to `std::filesystem::exists`, and finally calls `_std_fs_get_stats` . `_std_fs_get_stats` is slow if the argument is a netwok path. Signed-off-by: Jackson Sun <[email protected]>
1 parent 9229cf3 commit ae04b6e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libutil/filesystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,15 @@ Filesystem::path_is_absolute(string_view path, bool dot_is_absolute)
330330
bool
331331
Filesystem::exists(string_view path) noexcept
332332
{
333+
#ifdef _WIN32
334+
// filesystem::exists is slow on Windows for network paths, so use the
335+
// WinAPI directly
336+
return INVALID_FILE_ATTRIBUTES
337+
!= GetFileAttributesW(Strutil::utf8_to_utf16wstring(path).c_str());
338+
#else
333339
error_code ec;
334340
return filesystem::exists(u8path(path), ec);
341+
#endif
335342
}
336343

337344

0 commit comments

Comments
 (0)