gcc/libstdc++-v3/include
Jonathan Wakely 71e093897c PR libstdc++/87749 fix (and optimize) string move construction
The move constructor for the SSO string uses assign(const basic_string&)
when either:

(1) the source string is "local" and so the contents of the small string
buffer need to be copied, or

(2) the allocator does not propagate and is_always_equal is false.

Case (1) is suboptimal, because the assign member is not noexcept and
the compiler isn't smart enough to see it won't actually throw in this
case. This causes extra code in the move assignment operator so that any
exception will be turned into a call to std::terminate. This can be
fixed by copying small strings inline instead of calling assign.

Case (2) is a bug, because the specific instances of the allocators
could be equal even if is_always_equal is false. This can result in an
unnecessary deep copy (and potentially-throwing allocation) when the
storage should be moved. This can be fixed by simply checking if the
allocators are equal.

	PR libstdc++/87749
	* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
	(basic_string::operator=(basic_string&&)): For short strings copy the
	buffer inline. Only fall back to using assign(const basic_string&) to
	do a deep copy when reallocation is needed.
	* testsuite/21_strings/basic_string/modifiers/assign/char/87749.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/assign/char/
	move_assign_optim.cc: New test.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/87749.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/
	move_assign_optim.cc: New test.

From-SVN: r265493
2018-10-25 16:34:04 +01:00
..
backward
bits PR libstdc++/87749 fix (and optimize) string move construction 2018-10-25 16:34:04 +01:00
c
c_compatibility
c_global cstddef: Add versioned namespace. 2018-10-24 05:20:35 +00:00
c_std
debug 2018-10-24 François Dumont <fdumont@gcc.gnu.org> 2018-10-24 05:40:25 +00:00
decimal
experimental Fix versioned namespace macros for Networking TS 2018-10-16 17:12:51 +01:00
ext Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00
parallel
precompiled
profile
std re PR libstdc++/87619 (sizeof(std::variant) can be reduced if its variant_size is UCHAR_MAX) 2018-10-17 22:08:51 +03:00
tr1
tr2
Makefile.am Initial commit of Networking TS implementation 2018-10-12 11:50:15 +01:00
Makefile.in Initial commit of Networking TS implementation 2018-10-12 11:50:15 +01:00