From 738cfb00f7cf6d4e760fe2d5346f478937f55e83 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Fri, 21 Aug 2020 23:31:02 +0430 Subject: [PATCH 1/2] Improve vector growth performance near max_size --- stl/inc/vector | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/vector b/stl/inc/vector index 5a18de75a39..4157902eb13 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -1617,7 +1617,7 @@ private: const size_type _Oldcapacity = capacity(); if (_Oldcapacity > max_size() - _Oldcapacity / 2) { - return _Newsize; // geometric growth would overflow + return max_size(); // geometric growth would overflow } const size_type _Geometric = _Oldcapacity + _Oldcapacity / 2; From 771a1d46956b510ef88c07d374cfeb5ebb30c4b4 Mon Sep 17 00:00:00 2001 From: Hamid Reza Arzaghi Date: Mon, 24 Aug 2020 22:27:00 +0430 Subject: [PATCH 2/2] update vector --- stl/inc/vector | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stl/inc/vector b/stl/inc/vector index 4157902eb13..1ee836bad12 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -1615,9 +1615,10 @@ private: size_type _Calculate_growth(const size_type _Newsize) const { // given _Oldcapacity and _Newsize, calculate geometric growth const size_type _Oldcapacity = capacity(); + const auto _Max = max_size(); - if (_Oldcapacity > max_size() - _Oldcapacity / 2) { - return max_size(); // geometric growth would overflow + if (_Oldcapacity > _Max - _Oldcapacity / 2) { + return _Max; // geometric growth would overflow } const size_type _Geometric = _Oldcapacity + _Oldcapacity / 2;