[llvm] r188081 - Make directory iterator sentinels free.
Benjamin Kramer
benny.kra at googlemail.com
Fri Aug 9 10:03:40 PDT 2013
Author: d0k
Date: Fri Aug 9 12:03:39 2013
New Revision: 188081
URL: http://llvm.org/viewvc/llvm-project?rev=188081&view=rev
Log:
Make directory iterator sentinels free.
This trades some complexity in operator== for not introducing static objects
into any functions using recursive directory iterators.
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=188081&r1=188080&r2=188081&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Fri Aug 9 12:03:39 2013
@@ -869,7 +869,7 @@ public:
}
/// Construct end iterator.
- directory_iterator() : State(new detail::DirIterState) {}
+ directory_iterator() : State(0) {}
// No operator++ because we need error_code.
directory_iterator &increment(error_code &ec) {
@@ -881,6 +881,12 @@ public:
const directory_entry *operator->() const { return &State->CurrentEntry; }
bool operator==(const directory_iterator &RHS) const {
+ if (State == RHS.State)
+ return true;
+ if (RHS.State == 0)
+ return State->CurrentEntry == directory_entry();
+ if (State == 0)
+ return RHS.State->CurrentEntry == directory_entry();
return State->CurrentEntry == RHS.State->CurrentEntry;
}
@@ -920,7 +926,7 @@ public:
}
// No operator++ because we need error_code.
recursive_directory_iterator &increment(error_code &ec) {
- static const directory_iterator end_itr;
+ const directory_iterator end_itr;
if (State->HasNoPushRequest)
State->HasNoPushRequest = false;
@@ -967,7 +973,7 @@ public:
assert(State && "Cannot pop and end itertor!");
assert(State->Level > 0 && "Cannot pop an iterator with level < 1");
- static const directory_iterator end_itr;
+ const directory_iterator end_itr;
error_code ec;
do {
if (ec)
More information about the llvm-commits
mailing list