<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 31, 2014 at 10:14 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"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Dec 31, 2014, at 6:47 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><br><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Wed, Dec 31, 2014 at 3:33 PM, Michael Gottesman<span> </span><span dir="ltr"><<a href="mailto:mgottesman@apple.com" target="_blank">mgottesman@apple.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: mgottesman<br>Date: Wed Dec 31 17:33:24 2014<br>New Revision: 225055<br><br>URL:<span> </span><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>   <span> </span>llvm/trunk/include/llvm/ADT/TinyPtrVector.h<br>   <span> </span>llvm/trunk/unittests/ADT/TinyPtrVectorTest.cpp<br><br>Modified: llvm/trunk/include/llvm/ADT/TinyPtrVector.h<br>URL:<span> </span><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></div></div></div></blockquote><div><br></div></span><div>That is not the reason that I did this.</div><div><br></div><div>The reason I did this was from the perspective of API completeness when one is looking and exploring the class. I can imagine a user who is not familiar with ArrayRef’s constructors wondering where this constructor is given the raison d’être of the class. That being said I am not attached to it and I am willing to remove it.</div></div></div></blockquote><div><br>If the test pass without I'd suggest removing it (& if the tests don't pass when you remove it, I'd be curious to understand why). We're pretty pervasively using the single-arg ArrayRef ctor, so I doubt it'd take too long for a new developer to discover the idiom & become familiar with it.<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Michael</div></font></span><div><div class="h5"><div><br></div><blockquote type="cite"><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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:<span> </span><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" target="_blank">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></blockquote></div></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>