From 500ed210e0a28f5051122d9f4cdcc8c52d282ea7 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Fri, 7 Jan 2022 09:54:21 -0800 Subject: [PATCH] Use insert() with ranges instead of reserve STL implementation of insert() is generally smart enough to reserve storage before hand. No need to do reserve() followed by for each loop Test: th Change-Id: I36e88c121868b97ea525b292a67b36983c530e56 --- fs_mgr/libsnapshot/cow_reader.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs_mgr/libsnapshot/cow_reader.cpp b/fs_mgr/libsnapshot/cow_reader.cpp index 20030b940..9b5fd2aec 100644 --- a/fs_mgr/libsnapshot/cow_reader.cpp +++ b/fs_mgr/libsnapshot/cow_reader.cpp @@ -475,10 +475,7 @@ bool CowReader::PrepMergeOps() { std::sort(other_ops.begin(), other_ops.end(), std::greater()); } - merge_op_blocks->reserve(merge_op_blocks->size() + other_ops.size()); - for (auto block : other_ops) { - merge_op_blocks->emplace_back(block); - } + merge_op_blocks->insert(merge_op_blocks->end(), other_ops.begin(), other_ops.end()); num_total_data_ops_ = merge_op_blocks->size(); if (header_.num_merge_ops > 0) {