ustring: TODO to avoid copies from operator string + C++20 move from outstreams
I think these are worth doing, once ABI-break and C++20 come around respectively.
What do others think?
For operator std::string()
is there any risk of breakage? I can't see how, if we overload on both const&
and &&
, unless someone currently captures the value from operator std::string() const
by auto const&
and extends the lifetime of that temporary, which won't happen once it returns a reference to the member. But such code is probably suspect anyway, isn't it? And I don't think is justification to keep silently copying on convert.
The move(stream).str()
seems to be a no-brainer, clawing back a bit of performance from what is probably overall a bad picture due to using streams and having to copy again via GLib. Is there any way to avoid the latter, too?
commit 615efbd2cff735c0468a9e6e7d42af050a2af850 (HEAD -> dboles/ustring-TODOs, origin-ssh/dboles/ustring-TODOs)
Author: Daniel Boles <dboles.src@gmail.com>
Date: Tue Dec 12 15:54:31 2023 +0000
ustring: Add TODOs for C++20 move from outstreams
C++20 adds `ostream.str() &&` for rvalue `this`, which will move out the
stream's owned string. We can use that once we are on C++20 to avoid the
extra copy of the string (although we do then copy that AGAIN via GLib!)
commit e3b91d509a1d51241d9aaae8a1bab0966adf2024
Author: Daniel Boles <dboles.src@gmail.com>
Date: Tue Dec 12 15:50:28 2023 +0000
ustring: TODO to avoid copies from operator string
Our conversion operator to std::string always returns a copy but that is
wasteful when it could be a const& reference or moved-out from an rvalue
– especially bad since conversions can occur silently & harm performance
without users realising. We can split to const&/&& overloads at next ABI