Commit 02f17a8c authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[clang-tidy] Reserve space in vectors before pushing

This reserves space in a newly several newly created vectors before
pushing a known number of elements.

Change-Id: If3ba016395e7b509ced549b57279a049125c5d7c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2649034Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72318}
parent e284517b
......@@ -180,6 +180,7 @@ FrameState CreateJavaScriptBuiltinContinuationFrameState(
// to be the second value in the translation when creating stack crawls
// (e.g. Error.stack) of optimized JavaScript frames.
std::vector<Node*> actual_parameters;
actual_parameters.reserve(stack_parameter_count);
for (int i = 0; i < stack_parameter_count; ++i) {
actual_parameters.push_back(stack_parameters[i]);
}
......
......@@ -384,6 +384,7 @@ Node* RawMachineAssembler::CreateNodeFromPredecessors(
return sidetable[predecessors.front()->id().ToSize()];
}
std::vector<Node*> inputs;
inputs.reserve(predecessors.size());
for (BasicBlock* predecessor : predecessors) {
inputs.push_back(sidetable[predecessor->id().ToSize()]);
}
......@@ -410,6 +411,7 @@ void RawMachineAssembler::MakePhiBinary(Node* phi, int split_point,
left_input = NodeProperties::GetValueInput(phi, 0);
} else {
std::vector<Node*> inputs;
inputs.reserve(left_input_count);
for (int i = 0; i < left_input_count; ++i) {
inputs.push_back(NodeProperties::GetValueInput(phi, i));
}
......
......@@ -151,6 +151,7 @@ searchInTextByLinesImpl(V8InspectorSession* session, const String16& text,
scriptRegexpMatchesByLines(*regex.get(), text);
std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> result;
result.reserve(matches.size());
for (const auto& match : matches)
result.push_back(buildObjectForSearchMatch(match.first, match.second));
return result;
......
......@@ -74,6 +74,7 @@ class ConsoleHelper {
void reportCallWithDefaultArgument(ConsoleAPIType type,
const String16& message) {
std::vector<v8::Local<v8::Value>> arguments;
arguments.reserve(m_info.Length());
for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]);
if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message));
reportCall(type, arguments);
......
......@@ -1997,6 +1997,7 @@ Callable* ImplementationVisitor::LookupCallable(
for (size_t candidate : candidates) {
if (candidate != best && !is_better_candidate(best, candidate)) {
std::vector<Signature> candidate_signatures;
candidate_signatures.reserve(candidates.size());
for (size_t i : candidates) {
candidate_signatures.push_back(overload_signatures[i]);
}
......
......@@ -58,6 +58,7 @@ SourceId SourceFileMap::GetSourceId(const std::string& path) {
std::vector<SourceId> SourceFileMap::AllSources() {
SourceFileMap& self = Get();
std::vector<SourceId> result;
result.reserve(static_cast<int>(self.sources_.size()));
for (int i = 0; i < static_cast<int>(self.sources_.size()); ++i) {
result.push_back(SourceId(i));
}
......
......@@ -1312,6 +1312,7 @@ base::Optional<ParseResult> MakeEnumDeclaration(
name_type_expression->pos = name_identifier->pos;
std::vector<Declaration*> entry_decls;
entry_decls.reserve(entries.size());
for (const auto& entry : entries) {
entry_decls.push_back(MakeNode<AbstractTypeDeclaration>(
entry.name, AbstractTypeFlag::kNone,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment