[llvm] r226424 - Hide the state of TinyPtrVector and remove the single element constructor.

Michael Gottesman mgottesman at apple.com
Sun Jan 18 18:09:54 PST 2015


Author: mgottesman
Date: Sun Jan 18 20:09:54 2015
New Revision: 226424

URL: http://llvm.org/viewvc/llvm-project?rev=226424&view=rev
Log:
Hide the state of TinyPtrVector and remove the single element constructor.

There is no reason for this state to be exposed as public. The single element
constructor was superfulous in light of the single element ArrayRef
constructor.

Modified:
    llvm/trunk/include/llvm/ADT/TinyPtrVector.h

Modified: llvm/trunk/include/llvm/ADT/TinyPtrVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/TinyPtrVector.h?rev=226424&r1=226423&r2=226424&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/TinyPtrVector.h (original)
+++ llvm/trunk/include/llvm/ADT/TinyPtrVector.h Sun Jan 18 20:09:54 2015
@@ -25,11 +25,14 @@ namespace llvm {
 template <typename EltTy>
 class TinyPtrVector {
 public:
-  typedef llvm::SmallVector<EltTy, 4> VecTy;
-  typedef typename VecTy::value_type value_type;
+  using VecTy = llvm::SmallVector<EltTy, 4>;
+  using value_type = typename VecTy::value_type;
+  using PtrUnion = llvm::PointerUnion<EltTy, VecTy *>;
 
-  llvm::PointerUnion<EltTy, VecTy*> Val;
+private:
+  PtrUnion Val;
 
+public:
   TinyPtrVector() {}
   ~TinyPtrVector() {
     if (VecTy *V = Val.template dyn_cast<VecTy*>())
@@ -96,12 +99,13 @@ public:
     return *this;
   }
 
-  /// Constructor from a single element.
-  explicit TinyPtrVector(EltTy Elt) : Val(Elt) {}
-
   /// Constructor from an ArrayRef.
+  ///
+  /// This also is a constructor for individual array elements due to the single
+  /// element constructor for ArrayRef.
   explicit TinyPtrVector(ArrayRef<EltTy> Elts)
-      : Val(new VecTy(Elts.begin(), Elts.end())) {}
+      : Val(Elts.size() == 1 ? PtrUnion(Elts[0])
+                             : PtrUnion(new VecTy(Elts.begin(), Elts.end()))) {}
 
   // implicit conversion operator to ArrayRef.
   operator ArrayRef<EltTy>() const {





More information about the llvm-commits mailing list