gcc/libstdc++-v3
Jonathan Wakely cc3d7baf27 libstdc++: Optimize std::string::assign(Iter, Iter) [PR110945]
Calling string::assign(Iter, Iter) with "foreign" iterators (not the
string's own iterator or pointer types) currently constructs a temporary
string and then calls replace to copy the characters from it. That means
we copy from the iterators twice, and if the replace operation has to
grow the string then we also allocate twice.

By using *this = basic_string(first, last, get_allocator()) we only
perform a single allocation+copy and then do a cheap move assignment
instead of a second copy (and possible allocation). But that alternative
has to be done conditionally, so that we don't pessimize the native
iterator case (the string's own iterator and pointer types) which
currently select efficient overloads of replace which will not allocate
at all if the string already has sufficient capacity. For C++20 we can
extend that efficient case to work for any contiguous iterator with the
right value type, not just for the string's native iterators.

So the change is to inline the code that decides whether to work in
place or to allocate+copy (instead of deciding that via overload
resolution for replace), and for the allocate+copy case do a move
assignment instead of another call to replace.

For C++98 there is no change, as we can't do an efficient move
assignment anyway, so keep the current code.

We can also simplify assign(initializer_list<CharT>) because the backing
array for an initializer_list is always disjunct with *this, so most of
the code in _M_replace is not needed.

libstdc++-v3/ChangeLog:

	PR libstdc++/110945
	* include/bits/basic_string.h (basic_string::assign(Iter, Iter)):
	Dispatch to _M_replace or move assignment from a temporary,
	based on the iterator type.
2023-08-17 20:24:18 +01:00
..
config libstdc++: [_GLIBCXX_INLINE_VERSION] Add __cxa_call_terminate symbol export 2023-08-06 14:29:07 +02:00
doc libstdc++: Document --enable-cstdio=stdio_pure [PR110574] 2023-07-06 16:27:56 +01:00
include libstdc++: Optimize std::string::assign(Iter, Iter) [PR110945] 2023-08-17 20:24:18 +01:00
libsupc++ libstdc++: Make __cmp_cat::__unseq constructor consteval 2023-08-17 20:24:17 +01:00
po Update copyright years. 2023-01-16 11:52:17 +01:00
python libstdc++: Handle invalid values in std::chrono pretty printers 2023-08-11 14:33:01 +01:00
scripts Update copyright years. 2023-01-16 11:52:17 +01:00
src libstdc++: Fix several preprocessor directives 2023-07-30 15:52:00 +02:00
testsuite libstdc++: Add std::formatter specializations for extended float types 2023-08-17 20:24:18 +01:00
acinclude.m4 libstdc++: Fix --enable-cstdio=stdio_pure [PR110574] 2023-07-12 21:04:13 +01:00
aclocal.m4 libstdc++: Don't use gstdint.h anymore 2022-10-29 00:55:42 +01:00
ChangeLog Daily bump. 2023-08-17 00:17:21 +00: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
ChangeLog-2018
ChangeLog-2019
ChangeLog-2020
ChangeLog-2021
ChangeLog-2022 Rotate ChangeLog files. 2023-01-01 16:20:13 +01:00
config.h.in libstdc++: Fix --enable-cstdio=stdio_pure [PR110574] 2023-07-12 21:04:13 +01:00
configure libtool.m4: augment symcode for Solaris 11 2023-08-07 22:59:41 +02:00
configure.ac libstdc++: Fix iostream init for Clang on darwin [PR110432] 2023-06-30 15:35:02 +01:00
configure.host libstdc++: Fix up abi.exp FAILs on powerpc64-linux 2023-05-03 22:31:40 +02:00
crossconfig.m4 libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606] 2022-10-11 16:21:48 +01:00
fragment.am
linkage.m4
Makefile.am libstdc++: Enable building libstdc++.{a,so} when !HOSTED 2023-02-06 14:23:46 +00:00
Makefile.in libstdc++: Enable building libstdc++.{a,so} when !HOSTED 2023-02-06 14:23:46 +00:00
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.