Commit 2052c2e3 by Derek Mauro Committed by Copybara-Service

InlinedVector: Small improvement to the max_size() calculation

In some cases we can do a bit better by using
std::min(std::numeric_limits<size_type>::max() / 2, allocator<T>::max_size())

They may help in some cases, particularly on 32-bit platforms.

PiperOrigin-RevId: 471846886
Change-Id: I5bd63de5dd8aec3de6530a33d8904dd6e9bd015e
parent 152e9a18
...@@ -275,9 +275,10 @@ class InlinedVector { ...@@ -275,9 +275,10 @@ class InlinedVector {
size_type max_size() const noexcept { size_type max_size() const noexcept {
// One bit of the size storage is used to indicate whether the inlined // One bit of the size storage is used to indicate whether the inlined
// vector contains allocated memory. As a result, the maximum size that the // vector contains allocated memory. As a result, the maximum size that the
// inlined vector can express is half of the max for // inlined vector can express is the minimum of the limit of how many
// AllocatorTraits<A>::max_size(); // objects we can allocate and std::numeric_limits<size_type>::max() / 2.
return AllocatorTraits<A>::max_size(storage_.GetAllocator()) / 2; return (std::min)(AllocatorTraits<A>::max_size(storage_.GetAllocator()),
(std::numeric_limits<size_type>::max)() / 2);
} }
// `InlinedVector::capacity()` // `InlinedVector::capacity()`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment