[libcxx] r337765 - Recommit "Use possibly cached directory entry values when performing recursive directory iteration."
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 23 15:40:41 PDT 2018
Author: ericwf
Date: Mon Jul 23 15:40:41 2018
New Revision: 337765
URL: http://llvm.org/viewvc/llvm-project?rev=337765&view=rev
Log:
Recommit "Use possibly cached directory entry values when performing recursive directory iteration."
The initial patch didn't correctly handle systems when the dirent struct
didn't provide the d_type member. Specifically it set the cache to the incorrect state,
and claimed it was partially populated.
The updated version of this change correctly handles setting up the
cache when the file type is not known (aka file_type::none).
Modified:
libcxx/trunk/include/experimental/filesystem
libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp
Modified: libcxx/trunk/include/experimental/filesystem
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=337765&r1=337764&r2=337765&view=diff
==============================================================================
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Mon Jul 23 15:40:41 2018
@@ -2200,8 +2200,16 @@ private:
static __cached_data __create_iter_result(file_type __ft) {
__cached_data __data;
__data.__type_ = __ft;
- __data.__cache_type_ =
- __ft == file_type::symlink ? _IterSymlink : _IterNonSymlink;
+ __data.__cache_type_ = [&]() {
+ switch (__ft) {
+ case file_type::none:
+ return _Empty;
+ case file_type::symlink:
+ return _IterSymlink;
+ default:
+ return _IterNonSymlink;
+ }
+ }();
return __data;
}
Modified: libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp?rev=337765&r1=337764&r2=337765&view=diff
==============================================================================
--- libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp Mon Jul 23 15:40:41 2018
@@ -47,9 +47,10 @@ static file_type get_file_type(DirEntT *
}
return file_type::none;
}
+
template <class DirEntT>
static file_type get_file_type(DirEntT *ent, long) {
- return file_type::unknown;
+ return file_type::none;
}
static pair<string_view, file_type>
@@ -359,13 +360,13 @@ bool recursive_directory_iterator::__try
bool skip_rec = false;
error_code m_ec;
if (!rec_sym) {
- file_status st = curr_it.__entry_.symlink_status(m_ec);
+ file_status st(curr_it.__entry_.__get_sym_ft(&m_ec));
if (m_ec && status_known(st))
m_ec.clear();
if (m_ec || is_symlink(st) || !is_directory(st))
skip_rec = true;
} else {
- file_status st = curr_it.__entry_.status(m_ec);
+ file_status st(curr_it.__entry_.__get_ft(&m_ec));
if (m_ec && status_known(st))
m_ec.clear();
if (m_ec || !is_directory(st))
More information about the cfe-commits
mailing list