In C++ vectors are dynamic arrays.
Vectors are assigned memory in blocks of contiguous locations.
When the memory allocated for the vector falls short of storing
new elements, a new memory block is allocated to vector and all
elements are copied from the old location to the new location.
This reallocation of elements helps vectors to grow when required.
However, it is a costly operation and time complexity is involved
in this step is linear.
Try to use std::vector::reserve whenever possible if performance
matters.
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
// look for remaps we can un-remap
vector<pair<pg_t,
mempool::osdmap::vector<pair<int32_t,int32_t>>>> candidates;
+ candidates.reserve(tmp.pg_upmap_items.size());
for (auto& i : tmp.pg_upmap_items) {
if (to_skip.count(i.first))
continue;