diff options
author | Eduard Satdarov <sath@yandex-team.ru> | 2024-09-09 21:17:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-09 14:17:53 -0400 |
commit | b1b9b7b853fc4301aedd9ad6b7c22b75f5546b94 (patch) | |
tree | 626d13c7d9b79c4797ea6bc74fa4a73b42bfdc3a /libcxx/src | |
parent | 09b231cb38755e1bd122dbab9c57c4847bf64204 (diff) | |
download | llvm-b1b9b7b853fc4301aedd9ad6b7c22b75f5546b94.zip llvm-b1b9b7b853fc4301aedd9ad6b7c22b75f5546b94.tar.gz llvm-b1b9b7b853fc4301aedd9ad6b7c22b75f5546b94.tar.bz2 |
[libc++] Cache file attributes during directory iteration (#93316)
This patch adds caching of file attributes during directory iteration
on Windows. This improves the performance when working with files being
iterated on in a directory.
Diffstat (limited to 'libcxx/src')
-rw-r--r-- | libcxx/src/filesystem/directory_iterator.cpp | 12 | ||||
-rw-r--r-- | libcxx/src/filesystem/file_descriptor.h | 15 |
2 files changed, 17 insertions, 10 deletions
diff --git a/libcxx/src/filesystem/directory_iterator.cpp b/libcxx/src/filesystem/directory_iterator.cpp index dceb348..d7ed9a3 100644 --- a/libcxx/src/filesystem/directory_iterator.cpp +++ b/libcxx/src/filesystem/directory_iterator.cpp @@ -77,13 +77,13 @@ public: bool assign() { if (!wcscmp(__data_.cFileName, L".") || !wcscmp(__data_.cFileName, L"..")) return false; - // FIXME: Cache more of this - // directory_entry::__cached_data cdata; - // cdata.__type_ = get_file_type(__data_); - // cdata.__size_ = get_file_size(__data_); - // cdata.__write_time_ = get_write_time(__data_); __entry_.__assign_iter_entry( - __root_ / __data_.cFileName, directory_entry::__create_iter_result(detail::get_file_type(__data_))); + __root_ / __data_.cFileName, + directory_entry::__create_iter_cached_result( + detail::get_file_type(__data_), + detail::get_file_size(__data_), + detail::get_file_perm(__data_), + detail::get_write_time(__data_))); return true; } diff --git a/libcxx/src/filesystem/file_descriptor.h b/libcxx/src/filesystem/file_descriptor.h index f86eb60..db66ad5 100644 --- a/libcxx/src/filesystem/file_descriptor.h +++ b/libcxx/src/filesystem/file_descriptor.h @@ -97,11 +97,18 @@ inline uintmax_t get_file_size(const WIN32_FIND_DATAW& data) { return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow; } inline file_time_type get_write_time(const WIN32_FIND_DATAW& data) { - ULARGE_INTEGER tmp; + using detail::fs_time; const FILETIME& time = data.ftLastWriteTime; - tmp.u.LowPart = time.dwLowDateTime; - tmp.u.HighPart = time.dwHighDateTime; - return file_time_type(file_time_type::duration(tmp.QuadPart)); + auto ts = filetime_to_timespec(time); + if (!fs_time::is_representable(ts)) + return file_time_type::min(); + return fs_time::convert_from_timespec(ts); +} +inline perms get_file_perm(const WIN32_FIND_DATAW& data) { + unsigned st_mode = 0555; // Read-only + if (!(data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) + st_mode |= 0222; // Write + return static_cast<perms>(st_mode) & perms::mask; } #endif // !_LIBCPP_WIN32API |