[libcxx-commits] [libcxx] [libc++][vector] Fixes shrink_to_fit. (PR #97895)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 15 08:57:20 PDT 2024


https://github.com/ldionne approved this pull request.

It is somewhat frustrating to throw away the allocation we just made because it ends up being larger than the one we already had, but it makes us conforming and it does save us from having to copy the elements over to the new buffer. So technically we are saving some work (depending on the relative cost of everything, of course).

What we'd really like is a way to ask the allocator for *at most* n bytes. That way the allocator could instead report that it can only give us more than n bytes, and we'd likely prevent the system allocator from having to do additional work.

Anyway, this LGTM with a suggestion for the tests.

https://github.com/llvm/llvm-project/pull/97895


More information about the libcxx-commits mailing list