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

Nick Kledzik kledzik at apple.com
Tue Feb 4 11:32:41 PST 2014


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.



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/1eac4967/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alloc.patch
Type: application/octet-stream
Size: 6988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140204/1eac4967/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140204/1eac4967/attachment-0001.html>


More information about the llvm-commits mailing list