This is the mail archive of the
mailing list for the libstdc++ project.
Re: RFC: Allow moved-from strings to be non-empty
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 26 Oct 2018 00:34:38 +0200 (CEST)
- Subject: Re: RFC: Allow moved-from strings to be non-empty
- References: <20181025215349.GA12654@redhat.com>
- Reply-to: libstdc++ at gcc dot gnu dot org
On Thu, 25 Oct 2018, Jonathan Wakely wrote:
When an SSO string is contained in the small string buffer or has an
unequal allocator a move operation performs a copy, leaving the original
data in the moved-from string. Setting the length of the moved-from
string to zero is not required, so we can avoid two writes (to the
length member and to set the first character to nul) by leaving the
moved-from string unchanged.
This might be surprising to some users, who (wrongly) expect a string
to always be empty after a move. Is that acceptable?
It's worth noting that the current behaviour, where we do more work
than required, also surprises some people, e.g.
Some tests need to be adjusted due to the new behaviour, but they have
comments saying they're testing specific implementation details, so I
don't think needing to adjust them is an argument against making the
// NOTE: This makes use of the fact that we know how moveable
// is implemented on string (via swap). If the implementation changed
// this test may begin to fail.
Should we make this change?
I didn't read the patch, but from the description above, I say yes.
Interesting that I got my relocate patch in before, because after your
patch relocate probably helps a little less than before.