[llvm-commits] [llvm] r155907 - in /llvm/trunk: include/llvm/Support/YAMLParser.h lib/Support/YAMLParser.cpp

Benjamin Kramer benny.kra at googlemail.com
Tue May 1 03:20:00 PDT 2012


Author: d0k
Date: Tue May  1 05:19:59 2012
New Revision: 155907

URL: http://llvm.org/viewvc/llvm-project?rev=155907&view=rev
Log:
YAMLParser: get rid of global ctors & dtors.

Modified:
    llvm/trunk/include/llvm/Support/YAMLParser.h
    llvm/trunk/lib/Support/YAMLParser.cpp

Modified: llvm/trunk/include/llvm/Support/YAMLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLParser.h?rev=155907&r1=155906&r2=155907&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLParser.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLParser.h Tue May  1 05:19:59 2012
@@ -513,37 +513,44 @@
 /// @brief Iterator abstraction for Documents over a Stream.
 class document_iterator {
 public:
-  document_iterator() : Doc(NullDoc) {}
-  document_iterator(OwningPtr<Document> &D) : Doc(D) {}
+  document_iterator() : Doc(0) {}
+  document_iterator(OwningPtr<Document> &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<Document> &operator ->() {
-    return Doc;
+    return *Doc;
   }
 
 private:
-  static OwningPtr<Document> NullDoc;
-  OwningPtr<Document> &Doc;
+  bool isAtEnd() const {
+    return Doc == 0 || *Doc == 0;
+  }
+
+  OwningPtr<Document> *Doc;
 };
 
 }

Modified: llvm/trunk/lib/Support/YAMLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLParser.cpp?rev=155907&r1=155906&r2=155907&view=diff
==============================================================================
--- llvm/trunk/lib/Support/YAMLParser.cpp (original)
+++ llvm/trunk/lib/Support/YAMLParser.cpp Tue May  1 05:19:59 2012
@@ -2125,5 +2125,3 @@
   }
   return true;
 }
-
-OwningPtr<Document> document_iterator::NullDoc;





More information about the llvm-commits mailing list