[PATCH] A new ADT: StringRefNulTerminated

Dmitri Gribenko gribozavr at gmail.com
Sat Feb 23 15:30:23 PST 2013


On Sun, Feb 24, 2013 at 1:22 AM, Krzysztof Parzyszek
<kparzysz at codeaurora.org> wrote:
> On 2/23/2013 5:13 PM, Dmitri Gribenko wrote:
>>
>>
>> +    /// Construct an empty string ref.
>> +    /*implicit*/ StringRefNulTerminated() : StringRef() {}
>
>
> This is not quite the same as an empty null-terminated string.  I don't know
> if this was the intention, but it could cause confusion.  Maybe you could
> have a static const char in the class, initialized to 0, and initialize the
> StringRef with it instead?

Thanks.  I agree -- it might cause confusion.  But there's an easier way to fix:

    /// Construct an empty string ref.
    /*implicit*/ StringRefNulTerminated() : StringRef("") {}

Updated patch attached.

This raises a more important question: should we state that
StringRefNulTerminated::c_str() != NULL and include an assertion in
the 'const char*' constructor?

    /// Construct a string ref from a C string.
    explicit StringRefNulTerminated(const char *Str) : StringRef(Str) {}

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: string-ref-nul-terminated-v3.patch
Type: application/octet-stream
Size: 4041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130224/17a2259e/attachment.obj>


More information about the llvm-commits mailing list