On Fri, Jan 20, 2012 at 12:17 PM, Jim Grosbach <span dir="ltr"><<a href="mailto:grosbach@apple.com">grosbach@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hi Talin,<div><br></div><div>There's already a conversion operator to StringRef. Does that not handle things for you?</div><div><br></div><div><div> // Implicit conversion to StringRef. </div>
<div> operator StringRef() const { return str(); }</div></div></div></blockquote><div><br></div><div>This works when passing a SmallString as an argument, but not when calling members of SmallString. Currently you'd have to say something like theString.str().find(...). Now, admittedly it's only 6 extra characters, but I think it does make the code a little less readable.</div>
<div> </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><div> -j</div><div><div><div></div><div class="h5"><div>On Jan 19, 2012, at 11:42 PM, Talin wrote:</div>
<br></div></div><blockquote type="cite"><div><div></div><div class="h5">This patch adds many convenience methods to class SmallString:<div><div><ul><li>void assign(unsigned NumElts, char Elt);</li><li>void assign(in_iter S, in_iter E);</li>
<li>void assign(StringRef RHS);</li><li>void assign(const SmallVectorImpl<char> &RHS);</li>
<li>void append(in_iter S, in_iter E);</li><li>void append(StringRef RHS);</li><li>void append(const SmallVectorImpl<char> &RHS);</li><li>bool equals(StringRef RHS) const;</li><li>bool equals_lower(StringRef RHS) const;</li>
<li>int compare(StringRef RHS) const;</li><li>int compare_lower(StringRef RHS) const;</li><li>int compare_numeric(StringRef RHS) const;</li><li>bool startswith(StringRef Prefix) const;</li><li>bool endswith(StringRef Suffix) const;</li>
<li>size_t find(char C, size_t From = 0) const;</li><li>size_t find(StringRef Str, size_t From = 0) const;</li><li>size_t rfind(char C, size_t From = StringRef::npos) const;</li><li>size_t rfind(StringRef Str) const;</li>
<li>size_t find_first_of(char C, size_t From = 0) const;</li><li>size_t find_first_of(StringRef Chars, size_t From = 0) const;</li><li>size_t find_first_not_of(char C, size_t From = 0) const;</li><li>size_t find_first_not_of(StringRef Chars, size_t From = 0) const;</li>
<li>size_t find_last_of(char C, size_t From = StringRef::npos) const;</li><li>size_t find_last_of(StringRef Chars, size_t From = StringRef::npos) const;</li><li>size_t count(char C) const;</li><li>size_t count(StringRef Str) const;</li>
<li>StringRef substr(size_t Start, size_t N = StringRef::npos) const;</li><li>StringRef slice(size_t Start, size_t End) const;</li></ul></div><div>Most of the methods are taken directly from StringRef (find_x, compare_x, substr, and so on). My motivation for adding these methods is that often I find myself working with a SmallString instead of a StringRef, and it would be nice to call substr() for example directly without having to convert to a StringRef. Internally, of course, the methods simply convert the SmallString to a StringRef (which is extremely cheap), and then call the corresponding StringRef method. Doing it this way minimizes template expansion, since StringRef is a non-template class.</div>
<div><div><div><div><div><br></div><div>The 'assign' and 'append' methods are taken from standard STL, with additional overloads that are convenient for strings. For example, assign() now allows assigning to a SmallString from an iterator pair, which was not supported before.</div>
<div><br></div><div>(Note: I thought about adding support for assign/append/construct from an ArrayRef<char>, but that would add an additional include file dependency.)</div><div><br></div><div>This patch also includes many additions to the unit tests for SmallString, as well as some minor typographical cleanups in the comments in SmallString.h.</div>
<div><br></div>-- <br>-- Talin<br>
</div></div></div></div></div>
</div></div><span><smallstring.patch></span>_______________________________________________<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><br></blockquote></div><br></div></div></blockquote></div><br><br clear="all"><div>
<br></div>-- <br>-- Talin<br>