[libcxx-commits] [PATCH] D117332: [libc++] Make sure basic_string::reserve never shrinks in all standard modes

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 21 06:46:35 PST 2022


ldionne added a comment.

I am reconsidering my decision now. Let's put ourselves in the shoes of a programmer that wrote code in C++03 when the standard did say "if n < size(), this is a non-binding shrink-to-fit request". They most likely used `str.reserve()` with the exact expectation that it was going to `shrink_to_fit`.

API consistency is relevant for new code being written, however new code being written won't use `reserve()` because it's deprecated. So my opinion is now that if we change `reserve()` to never shrink, we're making the wrong tradeoff - existing code may change performance characteristics, and new code won't benefit from the consistency because new code won't use `reserve()` anyways.

Thoughts? If you agree, I'll turn this patch around and make `reserve(n)` never shrink in all standard modes, but I won't touch `reserve()` (so that it shrinks to fit in all standard modes).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117332/new/

https://reviews.llvm.org/D117332



More information about the libcxx-commits mailing list