gcc/libstdc++-v3/include
Jonathan Wakely 2b83bc6097 libstdc++: Optimize ref-count updates in COW std::string
Most ref-count updates in the COW string are done via the functions in
<ext/atomicity.h>, which will use non-atomic ops when the program is
known to be single-threaded. The _M_is_leaked() and _M_is_shared()
functions use __atomic_load_n directly, because <ext/atomicity.h>
doesn't provide a load operation. Those functions can check the
__is_single_threaded() predicate to avoid using __atomic_load_n when not
needed.

The move constructor for the fully-dynamic-string increments the
ref-count by either 2 or 1, for leaked or non-leaked strings
respectively. That can be changed to use a non-atomic store of 1 for all
non-shared strings. It can be non-atomic because even if the program is
multi-threaded, conflicting access to the rvalue object while it's being
moved from would be data race anyway. It can store 1 directly for all
non-shared strings because it doesn't matter whether the initial
refcount was -1 or 0, it should be 1 after the move constructor creates
a second owner.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string::_M_is_leaked): Use
	non-atomic load when __is_single_threaded() is true.
	(basic_string::_M_is_shared): Likewise.
	(basic_string::(basic_string&&)) [_GLIBCXX_FULLY_DYNAMIC_STRING]:
	Use non-atomic store when rvalue is not shared.
2021-12-01 15:00:33 +00:00
..
backward
bits libstdc++: Optimize ref-count updates in COW std::string 2021-12-01 15:00:33 +00:00
c
c_compatibility
c_global libstdc++: Enable type traits for wchar_t unconditionally [PR98725] 2021-10-09 00:57:49 +01:00
c_std
debug libstdc++: [_GLIBCXX_DEBUG] Reduce performance impact on std::erase_if 2021-11-20 16:11:22 +01:00
decimal
experimental libstdc++: [_GLIBCXX_DEBUG] Reduce performance impact on std::erase_if 2021-11-20 16:11:22 +01:00
ext libstdc++: Fix circular dependency for bitmap_allocator [PR103381] 2021-11-23 12:30:57 +00:00
parallel
precompiled libstdc++: Implement std::spanstream for C++23 2021-11-13 11:45:31 +00:00
pstl
std libstdc++: Add [[nodiscard]] to std::byteswap 2021-11-30 13:30:27 +01:00
tr1 libstdc++: Enable type traits for wchar_t unconditionally [PR98725] 2021-10-09 00:57:49 +01:00
tr2
Makefile.am libstdc++: Implement std::spanstream for C++23 2021-11-13 11:45:31 +00:00
Makefile.in libstdc++: Implement std::spanstream for C++23 2021-11-13 11:45:31 +00:00