[PATCH] D90386: [ADT] Add methods to SmallString for efficient concatenation

Nathan James via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 16:09:24 PDT 2020


njames93 added a comment.

In D90386#2363331 <https://reviews.llvm.org/D90386#2363331>, @dexonsmith wrote:

> I wonder, would it be valuable to do this for `Twine`? I'm thinking something like:
>
>   Optional<size_t> Twine::tryGetStorageLength() const;
>
> which returns `None` if there is a leaf whose size isn't known in constant time (say, other than `CStringKind`, `StdStringKind`, and `SmallStringKind`). Then change `Twine::toVector` to use this to reserve space:
>
>   void Twine::toVector(SmallVectorImpl<char> &Out) const {
>     if (auto Size = tryGetStorageLength())
>       Out.reserve(Out.size() + Size);
>   
>     raw_svector_ostream OS(Out);
>     print(OS);
>   }
>
> If so, might that cover this use case as well?

I can't see there being as much of a win in that case, but its definitely worth exploring, not in this patch though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90386



More information about the llvm-commits mailing list