diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h index 87117fdd4da..10239958f33 100644 --- a/include/llvm/Support/YAMLParser.h +++ b/include/llvm/Support/YAMLParser.h @@ -513,37 +513,44 @@ private: /// @brief Iterator abstraction for Documents over a Stream. class document_iterator { public: - document_iterator() : Doc(NullDoc) {} - document_iterator(OwningPtr &D) : Doc(D) {} + document_iterator() : Doc(0) {} + document_iterator(OwningPtr &D) : Doc(&D) {} bool operator ==(const document_iterator &Other) { - return Doc == Other.Doc; + if (isAtEnd() || Other.isAtEnd()) + return isAtEnd() && Other.isAtEnd(); + + return *Doc == *Other.Doc; } bool operator !=(const document_iterator &Other) { return !(*this == Other); } document_iterator operator ++() { - if (!Doc->skip()) { - Doc.reset(0); + assert(Doc != 0 && "incrementing iterator past the end."); + if (!(*Doc)->skip()) { + Doc->reset(0); } else { - Stream &S = Doc->stream; - Doc.reset(new Document(S)); + Stream &S = (*Doc)->stream; + Doc->reset(new Document(S)); } return *this; } Document &operator *() { - return *Doc; + return *Doc->get(); } OwningPtr &operator ->() { - return Doc; + return *Doc; } private: - static OwningPtr NullDoc; - OwningPtr &Doc; + bool isAtEnd() const { + return Doc == 0 || *Doc == 0; + } + + OwningPtr *Doc; }; } diff --git a/lib/Support/YAMLParser.cpp b/lib/Support/YAMLParser.cpp index fbb6ce95bd5..211ed2cdc3d 100644 --- a/lib/Support/YAMLParser.cpp +++ b/lib/Support/YAMLParser.cpp @@ -2125,5 +2125,3 @@ bool Document::expectToken(int TK) { } return true; } - -OwningPtr document_iterator::NullDoc;