diff options
author | Derek Mauro <dmauro@google.com> | 2022-09-02 11:27:49 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-09-02 11:28:21 -0700 |
commit | 2052c2e37c7554c52db3c117b3ad468924e10cd2 (patch) | |
tree | 58c1cac07a62b45e95081712164e40f8b23711cc /absl/container/inlined_vector.h | |
parent | 152e9a182675cea81ba38ae6784c9980132b0bdc (diff) |
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
Diffstat (limited to 'absl/container/inlined_vector.h')
-rw-r--r-- | absl/container/inlined_vector.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h index 42121228..08a47709 100644 --- a/absl/container/inlined_vector.h +++ b/absl/container/inlined_vector.h @@ -275,9 +275,10 @@ class InlinedVector { size_type max_size() const noexcept { // 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 - // inlined vector can express is half of the max for - // AllocatorTraits<A>::max_size(); - return AllocatorTraits<A>::max_size(storage_.GetAllocator()) / 2; + // inlined vector can express is the minimum of the limit of how many + // objects we can allocate and std::numeric_limits<size_type>::max() / 2. + return (std::min)(AllocatorTraits<A>::max_size(storage_.GetAllocator()), + (std::numeric_limits<size_type>::max)() / 2); } // `InlinedVector::capacity()` |