<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63603>63603</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] std::stable_sort allocates a temporary buffer for small number of elements
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ldionne
</td>
</tr>
</table>
<pre>
`std::stable_sort` currently allocates a temporary buffer whenever the elements are trivially copy assignable and there's 128 or more of them. However, when the elements are not trivially copy assignable, it always allocates, no matter how many elements we have. This means that we're paying the cost of an allocation even if we call `std::stable_sort` with like 3 elements that are not trivially copy assignable, which doesn't seem like the right tradeoff.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMktuOpDgMhp8m3FiNIBwKLrjo3lZpH2DvVyaYSnZzKCWmEG8_Cj2tGmlmWiMhIUH8-bPzY0rm5okm0b2J7r3AjXWIk11M8J6KOSzHJPoq8SKaV9G8JsbZ0r8pRBZ9BWqLkTzbA9DaoJApAQKTu4eI8YB5W1eKsGvy9KAIrAnIkiPPCTAScDQPg9YeoML9gA-d3ALQL_l4JCEvCWo5QIjgQiQIa_7hSvg77Jkq5F9nh5_pPvDvO-Qyw4B2xyM9_fNnH8AhM0XQYQeH_nhydwKNDyrhH20SOEKfgDUy7Nk0EtzxMP52yqiQOOui_-Sb4IEe5MGsmaTQWvhiv7thDdb8T9A8Dc5ufzTero3SsARKXsgLQyJyH7hsF81NZwAuFNa1LJapWcZmxIKmuh-GqmvqoSv0VI-N7ORaD3ODw6DasVVyUWpckdQoL5fCTLKSTdXLse6asWlLNat26ed1INn2Nc6ircihsaW1D1eGeCtMShtNfdNXTWFxJpvOBEppzayEfDsfmRMZp1z0Mm-3JNrKmsTpiWHD9szuD2XdO_xqnV8ndA0Rksu34Tc3U8y39rnwYot20sz3lKHyKuT1Zlhvc6mCE_Kabb6_Xu4x_EeKhbyeEyYhr-eQ3wIAAP__TMYpqw">