From 4f8939f88c94d522cc2c3b614a19bb8ecd47c1ae Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Thu, 6 Sep 2018 13:58:51 +0200 Subject: [PATCH] [torque] Prevent unnecessary copies by using const ref. Bug: v8:8015 Change-Id: I7f63989a897857c2258ec2bee59aed6100bc689e Reviewed-on: https://chromium-review.googlesource.com/1209346 Reviewed-by: Tobias Tebbi Commit-Queue: Florian Sattler Cr-Commit-Position: refs/heads/master@{#55685} --- src/torque/declaration-visitor.cc | 6 +++--- src/torque/file-visitor.cc | 2 +- src/torque/implementation-visitor.cc | 4 ++-- src/torque/types.cc | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/torque/declaration-visitor.cc b/src/torque/declaration-visitor.cc index 2f3a1fa869..f8878e7fa3 100644 --- a/src/torque/declaration-visitor.cc +++ b/src/torque/declaration-visitor.cc @@ -475,7 +475,7 @@ void DeclarationVisitor::Visit(TryLabelStatement* stmt) { } size_t i = 0; - for (auto p : block->parameters.names) { + for (const auto& p : block->parameters.names) { const Type* type = declarations()->GetType(block->parameters.types[i]); if (type->IsConstexpr()) { @@ -531,7 +531,7 @@ void DeclarationVisitor::GenerateHeader(std::string& file_name) { } if (declareParameters) { int index = 0; - for (auto parameter : builtin->parameter_names()) { + for (const auto& parameter : builtin->parameter_names()) { if (index >= firstParameterIndex) { new_contents_stream << ", k" << CamelifyString(parameter); } @@ -619,7 +619,7 @@ bool DeclarationVisitor::MarkVariableModified(const Variable* variable) { void DeclarationVisitor::DeclareSignature(const Signature& signature) { auto type_iterator = signature.parameter_types.types.begin(); - for (auto name : signature.parameter_names) { + for (const auto& name : signature.parameter_names) { const Type* t(*type_iterator++); if (name.size() != 0) { DeclareParameter(name, t); diff --git a/src/torque/file-visitor.cc b/src/torque/file-visitor.cc index c2e5aa7924..865b7b456d 100644 --- a/src/torque/file-visitor.cc +++ b/src/torque/file-visitor.cc @@ -13,7 +13,7 @@ namespace torque { Signature FileVisitor::MakeSignature(const CallableNodeSignature* signature) { LabelDeclarationVector definition_vector; - for (auto label : signature->labels) { + for (const auto& label : signature->labels) { LabelDeclaration def = {label.name, GetTypeVector(label.types)}; definition_vector.push_back(def); } diff --git a/src/torque/implementation-visitor.cc b/src/torque/implementation-visitor.cc index 62551d5271..a589080447 100644 --- a/src/torque/implementation-visitor.cc +++ b/src/torque/implementation-visitor.cc @@ -1595,7 +1595,7 @@ void ImplementationVisitor::GenerateParameter( void ImplementationVisitor::GenerateParameterList(const NameVector& list, size_t first) { - for (auto p : list) { + for (const auto& p : list) { if (first == 0) { GenerateParameter(p); } else { @@ -1998,7 +1998,7 @@ void ImplementationVisitor::GenerateLabelGoto(Label* label) { std::vector ImplementationVisitor::LabelsFromIdentifiers( const std::vector& names) { std::vector result; - for (auto name : names) { + for (const auto& name : names) { result.push_back(declarations()->LookupLabel(name)); } return result; diff --git a/src/torque/types.cc b/src/torque/types.cc index 261f085edb..223d7e98b8 100644 --- a/src/torque/types.cc +++ b/src/torque/types.cc @@ -255,7 +255,7 @@ bool Signature::HasSameTypesAs(const Signature& other) const { return false; } size_t i = 0; - for (auto l : labels) { + for (const auto& l : labels) { if (l.types != other.labels[i++].types) { return false; }