<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 31, 2014 at 3:33 PM, Michael Gottesman <span dir="ltr"><<a href="mailto:mgottesman@apple.com" target="_blank">mgottesman@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mgottesman<br>
Date: Wed Dec 31 17:33:24 2014<br>
New Revision: 225055<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=225055&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=225055&view=rev</a><br>
Log:<br>
Add 2x constructors for TinyPtrVector, one that takes in one elemenet and the other that takes in an ArrayRef<EltTy><br>
<br>
Currently one can only construct an empty TinyPtrVector. These are just missing<br>
elements of the API.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/TinyPtrVector.h<br>
    llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/TinyPtrVector.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/TinyPtrVector.h?rev=225055&r1=225054&r2=225055&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/TinyPtrVector.h?rev=225055&r1=225054&r2=225055&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/TinyPtrVector.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/TinyPtrVector.h Wed Dec 31 17:33:24 2014<br>
@@ -96,6 +96,13 @@ public:<br>
     return *this;<br>
   }<br>
<br>
+  /// Constructor from a single element.<br>
+  explicit TinyPtrVector(EltTy Elt) : Val(Elt) {}<br></blockquote><div><br>Do you need this one? ArrayRef<T> is already implicitly constructible from a single T, so the other ctor you added should suffice for this case.<br><br>(that said, it's not uncommon that too many user-defined conversions fire and these sort of intermediate conversions are needed - so if that's what you've hit, that's cool)<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+  /// Constructor from an ArrayRef.<br>
+  explicit TinyPtrVector(ArrayRef<EltTy> Elts)<br>
+      : Val(new VecTy(Elts.begin(), Elts.end())) {}<br>
+<br>
   // implicit conversion operator to ArrayRef.<br>
   operator ArrayRef<EltTy>() const {<br>
     if (Val.isNull())<br>
<br>
Modified: llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp?rev=225055&r1=225054&r2=225055&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp?rev=225055&r1=225054&r2=225055&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp (original)<br>
+++ llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp Wed Dec 31 17:33:24 2014<br>
@@ -412,3 +412,29 @@ TYPED_TEST(TinyPtrVectorTest, InsertRang<br>
 }<br>
<br>
 }<br>
+<br>
+TEST(TinyPtrVectorTest, SingleEltCtorTest) {<br>
+  int v = 55;<br>
+  TinyPtrVector<int *> V(&v);<br>
+<br>
+  EXPECT_TRUE(V.size() == 1);<br>
+  EXPECT_FALSE(V.empty());<br>
+  EXPECT_TRUE(V.front() == &v);<br>
+}<br>
+<br>
+TEST(TinyPtrVectorTest, ArrayRefCtorTest) {<br>
+  int data_array[128];<br>
+  std::vector<int *> data;<br>
+<br>
+  for (unsigned i = 0, e = 128; i != e; ++i) {<br>
+    data_array[i] = 324 - int(i);<br>
+    data.push_back(&data_array[i]);<br>
+  }<br>
+<br>
+  TinyPtrVector<int *> V(data);<br>
+  EXPECT_TRUE(V.size() == 128);<br>
+  EXPECT_FALSE(V.empty());<br>
+  for (unsigned i = 0, e = 128; i != e; ++i) {<br>
+    EXPECT_TRUE(V[i] == data[i]);<br>
+  }<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>