r206406 - More minor refactoring. Updated for const-correctness, moved another deleted function to be private, 0 -> nullptr and some style corrections. No functional changes intended.
Aaron Ballman
aaron at aaronballman.com
Wed Apr 16 10:44:02 PDT 2014
Author: aaronballman
Date: Wed Apr 16 12:44:02 2014
New Revision: 206406
URL: http://llvm.org/viewvc/llvm-project?rev=206406&view=rev
Log:
More minor refactoring. Updated for const-correctness, moved another deleted function to be private, 0 -> nullptr and some style corrections. No functional changes intended.
Modified:
cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
Modified: cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyUtil.h?rev=206406&r1=206405&r2=206406&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyUtil.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyUtil.h Wed Apr 16 12:44:02 2014
@@ -166,18 +166,20 @@ class CopyOnWriteVector {
std::vector<T> 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<T>::const_iterator iterator;
+ typedef typename std::vector<T>::const_iterator const_iterator;
const std::vector<T> &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);
}
More information about the cfe-commits
mailing list