aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectProcess.cpp
diff options
context:
space:
mode:
authorPeng Liu <winner245@hotmail.com>2025-02-22 08:50:48 -0500
committerGitHub <noreply@github.com>2025-02-22 14:50:48 +0100
commit31824b2a11a8aa3e1d5c699cd0786ad666999abf (patch)
treed567d8f28b41388325967c53b5bf9ea25631d5f0 /lldb/source/Commands/CommandObjectProcess.cpp
parenteb9215739930cdffde4201a9be42a788ea46c63f (diff)
downloadllvm-31824b2a11a8aa3e1d5c699cd0786ad666999abf.zip
llvm-31824b2a11a8aa3e1d5c699cd0786ad666999abf.tar.gz
llvm-31824b2a11a8aa3e1d5c699cd0786ad666999abf.tar.bz2
[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.
Diffstat (limited to 'lldb/source/Commands/CommandObjectProcess.cpp')
0 files changed, 0 insertions, 0 deletions