From 41fb951f874977f4c28c27797cd0693ee17c1b15 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 31 Oct 2018 23:36:10 +0000 Subject: [VFS] Add support for "no_push" to VFS recursive iterators. The "regular" file system has a useful feature that makes it possible to stop recursing when using the recursive directory iterators. This functionality was missing for the VFS recursive iterator and this patch adds that. Differential revision: https://reviews.llvm.org/D53465 llvm-svn: 345793 --- llvm/lib/Support/VirtualFileSystem.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'llvm/lib/Support/VirtualFileSystem.cpp') diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 81ac5bbaa9cb..9440eacaa890 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2157,28 +2157,33 @@ vfs::recursive_directory_iterator::recursive_directory_iterator( : FS(&FS_) { directory_iterator I = FS->dir_begin(Path, EC); if (I != directory_iterator()) { - State = std::make_shared(); - State->push(I); + State = std::make_shared(); + State->Stack.push(I); } } vfs::recursive_directory_iterator & recursive_directory_iterator::increment(std::error_code &EC) { - assert(FS && State && !State->empty() && "incrementing past end"); - assert(!State->top()->path().empty() && "non-canonical end iterator"); + assert(FS && State && !State->Stack.empty() && "incrementing past end"); + assert(!State->Stack.top()->path().empty() && "non-canonical end iterator"); vfs::directory_iterator End; - if (State->top()->type() == sys::fs::file_type::directory_file) { - vfs::directory_iterator I = FS->dir_begin(State->top()->path(), EC); - if (I != End) { - State->push(I); - return *this; + + if (State->HasNoPushRequest) + State->HasNoPushRequest = false; + else { + if (State->Stack.top()->type() == sys::fs::file_type::directory_file) { + vfs::directory_iterator I = FS->dir_begin(State->Stack.top()->path(), EC); + if (I != End) { + State->Stack.push(I); + return *this; + } } } - while (!State->empty() && State->top().increment(EC) == End) - State->pop(); + while (!State->Stack.empty() && State->Stack.top().increment(EC) == End) + State->Stack.pop(); - if (State->empty()) + if (State->Stack.empty()) State.reset(); // end iterator return *this; -- cgit v1.2.3