[libcxx-commits] [PATCH] D157776: [libc++] Eliminate extra allocations from `std::move(oss).str()`
Piotr Fusik via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 28 15:13:52 PDT 2023
pfusik added inline comments.
================
Comment at: libcxx/include/sstream:410
+ }();
__str_.clear();
__init_buf_ptrs();
----------------
philnik wrote:
> AMP999 wrote:
> > philnik wrote:
> > > pfusik wrote:
> > > > I think we don't need this `__str_.clear()` anymore.
> > > We do if the allocator is not equal after copying it. Then the old string isn't cleared.
> > Copies are equal by definition. But if the old string fits in the small-string buffer, the old string won't be cleared, either.
> Right. In that case the `clear()` is indeed redundant. The old string will be cleared, but even if that wasn't the case, there is no requirement that the string is cleared.
There is one:
> `basic_string<charT, traits, Allocator> str() &&;`
> Postconditions: The underlying character sequence `buf` is empty (...)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157776/new/
https://reviews.llvm.org/D157776
More information about the libcxx-commits
mailing list