Optimize vector initialization and preallocation in desc_builder.cc. This change adds `reserve()` calls to preallocate capacity, reducing potential reallocations. Change-Id: I51fdfdbdfaf512c102a36c7af1022c4b57af857f Reviewed-on: https://gn-review.googlesource.com/c/gn/+/20060 Reviewed-by: Takuto Ikuta <tikuta@google.com> Commit-Queue: David Turner <digit@google.com> Reviewed-by: David Turner <digit@google.com>
diff --git a/src/gn/desc_builder.cc b/src/gn/desc_builder.cc index 093cad9..def45a3 100644 --- a/src/gn/desc_builder.cc +++ b/src/gn/desc_builder.cc
@@ -722,8 +722,10 @@ ValuePtr RenderGenDeps() { auto res = std::make_unique<base::ListValue>(); Label default_tc = target_->settings()->default_toolchain_label(); + const auto& gen_deps_pairs = target_->gen_deps(); std::vector<std::string> gen_deps; - for (const auto& pair : target_->gen_deps()) + gen_deps.reserve(gen_deps_pairs.size()); + for (const auto& pair : gen_deps_pairs) gen_deps.push_back(pair.label.GetUserVisibleName(default_tc)); std::sort(gen_deps.begin(), gen_deps.end()); for (const auto& dep : gen_deps)