[PATCH] D157010: [llvm][ADT] Make `Twine` aware of `StringLiteral`

Ben Langmuir via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 10:13:13 PDT 2023


benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

In D157010#4558150 <https://reviews.llvm.org/D157010#4558150>, @jansvoboda11 wrote:

> I don't think so. The use-case I'm thinking of is having a bunch of `const Twine &` objects and wanting to create a `SmallVector<const char *>` with lifetime that's independent from the strings referenced by the `Twine` objects (using `StringSaver` for example). Knowing that the `Twine` refers to single `const char *` with static lifetime would allow you to safely skip saving/allocating the string buffer. You can't skip that for `std::string`, since that might deallocate its buffer. Does that make sense?

Got it, sorry I thought this commit was self-contained and you were worried about the case in `toNullTerminatedStringRef` which would have allocated before but now does not, but I guess you have a follow-on commit that uses this new representation?  In that case, LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157010/new/

https://reviews.llvm.org/D157010



More information about the llvm-commits mailing list