Fields

hardware None
os None

Parameters

Fields

NameValue

Parameters

NameValue
git_commit commit 31824b2a11a8aa3e1d5c699cd0786ad666999abf
Author: Peng Liu <winner245@hotmail.com>
Date: Sat Feb 22 08:50:48 2025 -0500

[libc++] Fix shrink_to_fit to swap buffer only when capacity is strictly smaller (#127321)

The current implementation of the `shrink_to_fit()` function of
`basic_string` swaps to the newly allocated buffer when the new buffer
has the same capacity as the existing one. While this is not incorrect,
it is truly unnecessary to swap to an equally-sized buffer. With equal
capacity, we should keep using the existing buffer and simply deallocate
the new one, avoiding the extra work of copying elements.

The desired behavior was documented in the following comment within the
function:


https://github.com/llvm/llvm-project/blob/61ad08792a86e62309b982189a600f4342a38d91/libcxx/include/string#L3560-L3566

However, the existing implementation did not exactly conform to this
guideline, which is a QoI matter.

This PR modifies the `shrink_to_fit()` function to ensure that the
buffer is only swapped when the new allocation is strictly smaller than
the existing one. When the capacities are equal, the new buffer will be
discarded without copying the elements. This is achieved by including
the `==` check in the above conditional logic.
Filter

ldionne-old-macbook-results test results

Run Order Start Time Duration
Current 528215 2025-12-16T16:40:01 0:00:00
Previous 528129 2025-12-16T16:40:01 0:00:00
Baseline 485288 2025-12-16T16:40:01 0:00:00


Tests Summary

Status Group # # (B)
Performance Improvements 2 0
Added Tests 0 18
Unchanged Tests 88 72
Total Tests 90

Performance Improvements - execution_time Δ Previous Current σ Δ (B) σ (B)
729_abc_r -1.91% 19.016 18.654 0.135 0.00% 0.135
731_astcenc_r -1.23% 10.162 10.037 0.041 0.00% 0.041

Added Tests - execution_time
706_stockfish_r
707_ntest_r
709_cactus_r
710_omnetpp_r
721_gcc_r
723_llvm_r
727_cppcheck_r
729_abc_r
731_astcenc_r
734_vpr_r
735_gem5_r
736_ocio_r
737_gmsh_r
748_flightdm_r
750_sealcrypto_r
753_ns3_r
766_femflow_r
767_nest_r


Report Time: 0.12s