Skip to content

Commit a5f3868

Browse files
committed
perf: Speedup other file ops on Windows
Signed-off-by: Lumina Wang <lumina.wang@autodesk.com>
1 parent a6fd93a commit a5f3868

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/libutil/filesystem.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,30 @@ Filesystem::exists(string_view path) noexcept
346346
bool
347347
Filesystem::is_directory(string_view path) noexcept
348348
{
349+
#ifdef _WIN32
350+
DWORD attr = GetFileAttributesW(
351+
Strutil::utf8_to_utf16wstring(path).c_str());
352+
return attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY);
353+
#else
349354
error_code ec;
350355
return filesystem::is_directory(u8path(path), ec);
356+
#endif
351357
}
352358

353359

354360

355361
bool
356362
Filesystem::is_regular(string_view path) noexcept
357363
{
364+
#ifdef _WIN32
365+
DWORD attr = GetFileAttributesW(
366+
Strutil::utf8_to_utf16wstring(path).c_str());
367+
return attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)
368+
&& !(attr & FILE_ATTRIBUTE_REPARSE_POINT); // exclude symlinks
369+
#else
358370
error_code ec;
359371
return filesystem::is_regular_file(u8path(path), ec);
372+
#endif
360373
}
361374

362375

@@ -774,9 +787,18 @@ Filesystem::last_write_time(string_view path, std::time_t time) noexcept
774787
uint64_t
775788
Filesystem::file_size(string_view path) noexcept
776789
{
790+
#ifdef _WIN32
791+
WIN32_FILE_ATTRIBUTE_DATA data {};
792+
if (!GetFileAttributesExW(Strutil::utf8_to_utf16wstring(path).c_str(),
793+
GetFileExInfoStandard, &data))
794+
return 0;
795+
return (static_cast<uint64_t>(data.nFileSizeHigh) << 32)
796+
| static_cast<uint64_t>(data.nFileSizeLow);
797+
#else
777798
error_code ec;
778799
uint64_t sz = filesystem::file_size(u8path(path), ec);
779800
return ec ? 0 : sz;
801+
#endif
780802
}
781803

782804

0 commit comments

Comments
 (0)