gcc/libstdc++-v3
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
..
config testsuite_containers.h (forward_members_unordered<>::forward_members_unordered (const value_type&)): Add local_iterator pre and post increment checks. 2018-10-20 20:00:45 +00:00
doc
include PR libstdc++/87749 fix (and optimize) string move construction 2018-10-25 16:34:04 +01:00
libsupc++
po
python Define std::string and related typedefs outside __cxx11 namespace 2018-10-09 14:06:46 +01:00
scripts
src PR libstdc++/87641 correctly initialize accumulator in valarray::sum() 2018-10-18 16:38:50 +01:00
testsuite PR libstdc++/87749 fix (and optimize) string move construction 2018-10-25 16:34:04 +01:00
ChangeLog PR libstdc++/87749 fix (and optimize) string move construction 2018-10-25 16:34:04 +01:00
ChangeLog-1998
ChangeLog-1999
ChangeLog-2000
ChangeLog-2001
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
Makefile.am
Makefile.in
README
acinclude.m4 Define _GLIBCXX_USE_DEV_RANDOM as replacement for _GLIBCXX_USE_RANDOM_TR1 2018-10-16 15:49:29 +01:00
aclocal.m4
config.h.in Use autoconf to check for features needed by Networking TS 2018-10-16 17:12:32 +01:00
configure Use autoconf to check for features needed by Networking TS 2018-10-16 17:12:32 +01:00
configure.ac Use autoconf to check for features needed by Networking TS 2018-10-16 17:12:32 +01:00
configure.host
crossconfig.m4 Define _GLIBCXX_USE_DEV_RANDOM as replacement for _GLIBCXX_USE_RANDOM_TR1 2018-10-16 15:49:29 +01:00
fragment.am
linkage.m4

README

file: libstdc++-v3/README

New users may wish to point their web browsers to the file
index.html in the 'doc/html' subdirectory.  It contains brief
building instructions and notes on how to configure the library in
interesting ways.