[PATCH] StringRef::copy should never copy empty strings
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 23 14:56:22 PDT 2016
> On Mar 23, 2016, at 2:23 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
> Looks good - thanks!
Thanks for the review. r264201.
>
> (you might be able to write "(size-t)0" as "0u" instead)
Funnily enough I thought about doing this but then got myself convinced that targets might exists where size_t isn’t unsigned. Anyway, I’m obviously being stupid here so committed with 0u.
Pete
>
> On Wed, Mar 23, 2016 at 2:22 PM, Pete Cooper <peter_cooper at apple.com <mailto:peter_cooper at apple.com>> wrote:
>
>> On Mar 23, 2016, at 1:57 PM, David Blaikie <dblaikie at gmail.com <mailto:dblaikie at gmail.com>> wrote:
>>
>> Presumably you could just "return *this" (or "return StringRef()”)
> Ah yeah, StringRef() is better than what I had. I do personally prefer it over ‘*this’ just because I like that data() will be nullptr.
>>
>> Perhaps you could test that the allocator is not invoked for that copy operation?
>
> Good point. Added that now.
>
> Cheers
> Pete
>
>
>>
>> On Wed, Mar 23, 2016 at 11:36 AM, Pete Cooper <peter_cooper at apple.com <mailto:peter_cooper at apple.com>> wrote:
>> Hi Mehdi, David
>>
>> This is a spin off from the discussion on Allocator.h and requesting that we allocate 0 bytes.
>>
>> Independent from whatever gets decided on Allocate behaviour, I think it would be best if StringRef::copy returns StringRef(nullptr, 0) whenever we try to copy an empty string. StringRef(“”) would also be fine if you prefer.
>>
>> This makes that change and adds test to the unit test for the new behavior.
>>
>> Cheers,
>> Pete
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160323/54577ef3/attachment.html>
More information about the llvm-commits
mailing list