[llvm-commits] [llvm] r120984 - in /llvm/trunk/include/llvm/ADT: SmallString.h SmallVector.h
Michael Spencer
bigcheesegs at gmail.com
Sun Dec 5 21:44:41 PST 2010
On Sun, Dec 5, 2010 at 11:40 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Dec 5, 2010, at 8:27 PM, Michael J. Spencer wrote:
>
>> Author: mspencer
>> Date: Sun Dec 5 22:27:42 2010
>> New Revision: 120984
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=120984&view=rev
>> Log:
>> Support/ADT: Move c_str() from SmallString to SmallVectorImpl. The Windows PathV2
>> implementation needs it for wchar_t and SmallVectorImpl in general.
>
> Hi Michael,
>
> 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.
- Michael Spencer
>>
>> Modified:
>> llvm/trunk/include/llvm/ADT/SmallString.h
>> llvm/trunk/include/llvm/ADT/SmallVector.h
>>
>> Modified: llvm/trunk/include/llvm/ADT/SmallString.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallString.h?rev=120984&r1=120983&r2=120984&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/SmallString.h (original)
>> +++ llvm/trunk/include/llvm/ADT/SmallString.h Sun Dec 5 22:27:42 2010
>> @@ -41,12 +41,6 @@
>> // Implicit conversion to StringRef.
>> operator StringRef() const { return str(); }
>>
>> - const char *c_str() {
>> - this->push_back(0);
>> - this->pop_back();
>> - return this->data();
>> - }
>> -
>> // Extra operators.
>> const SmallString &operator=(StringRef RHS) {
>> this->clear();
>>
>> Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=120984&r1=120983&r2=120984&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
>> +++ llvm/trunk/include/llvm/ADT/SmallVector.h Sun Dec 5 22:27:42 2010
>> @@ -340,6 +340,12 @@
>> return Result;
>> }
>>
>> + // TODO: Make this const, if it's safe...
>> + typename SuperClass::const_pointer c_str() {
>> + push_back(0);
>> + pop_back();
>> + return this->data();
>> + }
>>
>> void swap(SmallVectorImpl &RHS);
More information about the llvm-commits
mailing list