[llvm] r200331 - Add BumpPtrAllocator::allocateCopy() utilities

Eli Bendersky eliben at google.com
Tue Feb 4 13:21:08 PST 2014


On Tue, Feb 4, 2014 at 11:32 AM, Nick Kledzik <kledzik at apple.com> wrote:

>
> On Feb 1, 2014, at 9:41 AM, Eli Bendersky <eliben at google.com> wrote:
>
> It strikes me as strange to add a dependency for Allocator on StringRef
> for this case (and I guess on ArrayRef too). If this is a service StringRef
> needs from Allocator and not vice versa, wouldn't it make more sense to add
> this utility method to StringRef (taking an Allocator)?
>
>
> Ok, I’ve inverted the layering with this patch.  Allocator.h goes back to
> what it was and I’ve added a copy(BumpPtrAllocator &) method to StringRef
> and ArrayRef<>.  And the test cases move out of the allocator and into
> StringRef and ArrayRef.
>
>
>
>
Great. Thanks, Nick.

Eli


> The motivation for these utilities is that BumpPtrAllocator has a one line
> syntax for allocating and initializing a new *object* in the bump pointer
> pool:
>
>     Foo *myFoo = (myAllocator) Foo(args);
>
> But if you want to copy a string in to the bump pointer pool and get a
> StringRef to it, it is multiple steps.  With this patch, it is now just:
>
>     StringRef myCopy = myStr.copy(myAllocator);
>
> -Nick
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140204/ee089fe8/attachment.html>


More information about the llvm-commits mailing list