Commit 66398521 authored by Florian Sattler's avatar Florian Sattler Committed by Commit Bot

[torque] Refactored functions to prevent unnecessary copies

Bug: v8:8015
Change-Id: Ice0c5994ff5695c06be307c3e37d90daf14c643c
Reviewed-on: https://chromium-review.googlesource.com/1209763
Commit-Queue: Florian Sattler <sattlerf@google.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55691}
parent 51224eab
......@@ -1399,7 +1399,8 @@ LocationReference ImplementationVisitor::GetLocationReference(
return LocationReference(nullptr, result, {});
}
std::string ImplementationVisitor::RValueFlattenStructs(VisitResult result) {
std::string ImplementationVisitor::RValueFlattenStructs(
const VisitResult& result) {
if (result.declarable()) {
const Value* value = *result.declarable();
const Type* type = value->type();
......@@ -1422,7 +1423,7 @@ std::string ImplementationVisitor::RValueFlattenStructs(VisitResult result) {
}
VisitResult ImplementationVisitor::GenerateFetchFromLocation(
LocationExpression* location, LocationReference reference) {
LocationExpression* location, const LocationReference& reference) {
switch (location->kind) {
case AstNode::Kind::kIdentifierExpression:
return GenerateFetchFromLocation(
......@@ -1439,7 +1440,7 @@ VisitResult ImplementationVisitor::GenerateFetchFromLocation(
}
VisitResult ImplementationVisitor::GenerateFetchFromLocation(
FieldAccessExpression* expr, LocationReference reference) {
FieldAccessExpression* expr, const LocationReference& reference) {
if (reference.value != nullptr) {
return GenerateFetchFromLocation(reference);
}
......@@ -1455,7 +1456,7 @@ VisitResult ImplementationVisitor::GenerateFetchFromLocation(
}
void ImplementationVisitor::GenerateAssignToVariable(Variable* var,
VisitResult value) {
const VisitResult& value) {
if (var->type()->IsStructType()) {
if (value.type() != var->type()) {
std::stringstream s;
......@@ -1491,7 +1492,7 @@ void ImplementationVisitor::GenerateAssignToVariable(Variable* var,
void ImplementationVisitor::GenerateAssignToLocation(
LocationExpression* location, const LocationReference& reference,
VisitResult assignment_value) {
const VisitResult& assignment_value) {
if (reference.value != nullptr) {
Value* value = reference.value;
if (value->IsConst()) {
......@@ -1998,6 +1999,7 @@ void ImplementationVisitor::GenerateLabelGoto(Label* label) {
std::vector<Label*> ImplementationVisitor::LabelsFromIdentifiers(
const std::vector<std::string>& names) {
std::vector<Label*> result;
result.reserve(names.size());
for (const auto& name : names) {
result.push_back(declarations()->LookupLabel(name));
}
......
......@@ -48,22 +48,22 @@ class ImplementationVisitor : public FileVisitor {
return LocationReference({}, Visit(expr->array), Visit(expr->index));
}
std::string RValueFlattenStructs(VisitResult result);
std::string RValueFlattenStructs(const VisitResult& result);
VisitResult GenerateFetchFromLocation(LocationReference reference) {
VisitResult GenerateFetchFromLocation(const LocationReference& reference) {
const Value* value = reference.value;
return VisitResult(value->type(), value);
}
VisitResult GenerateFetchFromLocation(LocationExpression* location,
LocationReference reference);
const LocationReference& reference);
VisitResult GenerateFetchFromLocation(IdentifierExpression* expr,
LocationReference reference) {
const LocationReference& reference) {
return GenerateFetchFromLocation(reference);
}
VisitResult GenerateFetchFromLocation(FieldAccessExpression* expr,
LocationReference reference);
const LocationReference& reference);
VisitResult GenerateFetchFromLocation(ElementAccessExpression* expr,
LocationReference reference) {
const LocationReference& reference) {
Arguments arguments;
arguments.parameters = {reference.base, reference.index};
return GenerateCall("[]", arguments);
......@@ -183,11 +183,11 @@ class ImplementationVisitor : public FileVisitor {
VisitResult GenerateCopy(const VisitResult& to_copy);
void GenerateAssignToVariable(Variable* var, VisitResult value);
void GenerateAssignToVariable(Variable* var, const VisitResult& value);
void GenerateAssignToLocation(LocationExpression* location,
const LocationReference& reference,
VisitResult assignment_value);
const VisitResult& assignment_value);
void GenerateVariableDeclaration(const Variable* var);
......
......@@ -987,7 +987,7 @@ struct TorqueGrammar : Grammar {
MakeParameterListFromNameAndTypeList<true>)};
// Result: std::string
Symbol* OneOf(std::vector<std::string> alternatives) {
Symbol* OneOf(const std::vector<std::string>& alternatives) {
Symbol* result = NewSymbol();
for (const std::string& s : alternatives) {
result->AddRule(Rule({Token(s)}, YieldMatchedInput));
......
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