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

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 15:41:11 PDT 2020


dexonsmith added a comment.

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?


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