[llvm-commits] [llvm] r120984 - in /llvm/trunk/include/llvm/ADT: SmallString.h SmallVector.h

Chris Lattner clattner at apple.com
Thu Dec 9 00:25:40 PST 2010


On Dec 6, 2010, at 1:59 PM, Michael Spencer wrote:

> On Mon, Dec 6, 2010 at 4:03 PM, Chris Lattner <clattner at apple.com> wrote:
>> 
>> On Dec 5, 2010, at 9:44 PM, Michael Spencer wrote:
>> 
>>>> I don't think this makes sense, why not just cast data?  With wchar_t you usually need a multibyte 0 anyway.
>>>> 
>>>> -Chris
>>> 
>>> c_str() as implemented uses push_back to add the 0, thus we get a
>>> sizeof(wchar_t) byte null terminator. The reason this is needed is
>>> because I kept running into bugs trying to keep track of when I needed
>>> to add a null terminator. This way I can use c_str() exactly when
>>> passing the string to a Windows API function.
>> 
>> Oh right, but why add this to SmallVector?  It doesn't seem to make sense there.  If there are weird clients that want this in the system library, can't they either take a smallstring, or just do push_back(0) + pop_back() manually?
>> 
>> -Chris
> 
> They can't take a small string because that requires specifying the
> size, or templating on the size. And SmallString is char only.
> 
> Doing push/pop manually is what I was doing before. The problem is
> that it ends up littered all throughout the function before every
> system API call. The major difference is that the null termination is
> explicit and obvious in the function call when using .c_str().
> 
> If this is undesired, I'm also happy with adding a free-standing
> template <class T> typename
> SmallVectorImpl<T>::SuperClass::const_pointer c_str(SmallVectorImpl<T>
> &) function someplace and using that.

How about just making this a static inline function somewhere in libsupport that is used by the windows stuff?

-Chris



More information about the llvm-commits mailing list