From: Aaron Ballman Date: Wed, 16 Apr 2014 17:44:02 +0000 (+0000) Subject: More minor refactoring. Updated for const-correctness, moved another deleted function... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9780caa82c805bd02d5188f8f49a9dfab963e8c5;p=clang More minor refactoring. Updated for const-correctness, moved another deleted function to be private, 0 -> nullptr and some style corrections. No functional changes intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206406 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/Analyses/ThreadSafetyUtil.h b/include/clang/Analysis/Analyses/ThreadSafetyUtil.h index c5cd8fc639..c8e670b98d 100644 --- a/include/clang/Analysis/Analyses/ThreadSafetyUtil.h +++ b/include/clang/Analysis/Analyses/ThreadSafetyUtil.h @@ -166,18 +166,20 @@ class CopyOnWriteVector { std::vector Vect; }; + // No copy constructor or copy assignment. Use clone() with move assignment. CopyOnWriteVector(const CopyOnWriteVector &V) LLVM_DELETED_FUNCTION; + void operator=(const CopyOnWriteVector &V) LLVM_DELETED_FUNCTION; public: - CopyOnWriteVector() : Data(0) {} - CopyOnWriteVector(CopyOnWriteVector &&V) : Data(V.Data) { V.Data = 0; } + CopyOnWriteVector() : Data(nullptr) {} + CopyOnWriteVector(CopyOnWriteVector &&V) : Data(V.Data) { V.Data = nullptr; } ~CopyOnWriteVector() { destroy(); } // Returns true if this holds a valid vector. - bool valid() { return Data; } + bool valid() const { return Data; } // Returns true if this vector is writable. - bool writable() { return Data && Data->NumRefs == 1; } + bool writable() const { return Data && Data->NumRefs == 1; } // If this vector is not valid, initialize it to a valid vector. void init() { @@ -194,7 +196,7 @@ public: delete Data; else --Data->NumRefs; - Data = 0; + Data = nullptr; } // Make this vector writable, creating a copy if needed. @@ -212,28 +214,26 @@ public: // Create a lazy copy of this vector. CopyOnWriteVector clone() { return CopyOnWriteVector(Data); } - // No copy constructor or copy assignment. Use clone() with move assignment. - void operator=(const CopyOnWriteVector &V) LLVM_DELETED_FUNCTION; - - void operator=(CopyOnWriteVector &&V) { + CopyOnWriteVector &operator=(CopyOnWriteVector &&V) { destroy(); Data = V.Data; - V.Data = 0; + V.Data = nullptr; + return *this; } - typedef typename std::vector::const_iterator iterator; + typedef typename std::vector::const_iterator const_iterator; const std::vector &elements() const { return Data->Vect; } - iterator begin() const { return elements().cbegin(); } - iterator end() const { return elements().cend(); } + const_iterator begin() const { return elements().cbegin(); } + const_iterator end() const { return elements().cend(); } const T& operator[](unsigned i) const { return elements()[i]; } unsigned size() const { return Data ? elements().size() : 0; } // Return true if V and this vector refer to the same data. - bool sameAs(const CopyOnWriteVector& V) { return Data == V.Data; } + bool sameAs(const CopyOnWriteVector &V) const { return Data == V.Data; } // Clear vector. The vector must be writable. void clear() { @@ -242,7 +242,7 @@ public: } // Push a new element onto the end. The vector must be writable. - void push_back(const T& Elem) { + void push_back(const T &Elem) { assert(writable() && "Vector is not writable!"); Data->Vect.push_back(Elem); }