Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libcxx/include/__utility/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ void swap_value_representations(_Tp& __a, _Tp& __b) {
constexpr size_t __chunk = __value_size / __size;
constexpr size_t __rem = __value_size % __size;

// TODO: research better memswap algorithms
char __buffer[__size];

if constexpr (__chunk) {
for (std::size_t n = 0; n < __chunk; n++, __aptr += __size, __bptr += __size) {
__builtin_memcpy(__buffer, __aptr, __size);
__builtin_memmove(__aptr, __bptr, __size);
__builtin_memmove(__bptr, __buffer, __size);
__builtin_memcpy(__aptr, __bptr, __size);
__builtin_memcpy(__bptr, __buffer, __size);
}
}
if constexpr (__rem) {
__builtin_memcpy(__buffer, __aptr, __rem);
__builtin_memmove(__aptr, __bptr, __rem);
__builtin_memmove(__bptr, __buffer, __rem);
__builtin_memcpy(__aptr, __bptr, __rem);
__builtin_memcpy(__bptr, __buffer, __rem);
}
}
#endif
Expand Down
11 changes: 10 additions & 1 deletion libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ struct __uninitialized_size_tag {};
struct __init_with_sentinel_tag {};

template <class _CharT, class _Traits, class _Allocator>
class basic_string memberwise_trivially_relocatable {
class basic_string memberwise_trivially_relocatable
memberwise_replaceable {

private:
using __default_allocator_type = allocator<_CharT>;
Expand Down Expand Up @@ -3446,6 +3447,14 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
#endif
{

#if _LIBCPP_STD_VER >= 26
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't do this unless the allocator is replaceable, too. (Usually it will be, but not always)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That goes to show how little i know about allocators!

if constexpr(std::is_same_v<allocator_type, allocator<_CharT>>) {
std::swap_value_representations(*this, __str);
return;
}
#endif

_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
__alloc_traits::propagate_on_container_swap::value || __alloc_traits::is_always_equal::value ||
__alloc() == __str.__alloc(),
Expand Down