Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: tools/gn/function_forward_variables_from.cc

Issue 2219083002: Update GN toolchain_args to be a variable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge remote-tracking branch 'origin/master' into toolchain_args Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/format_test_data/067.golden ('k') | tools/gn/function_forward_variables_from_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_forward_variables_from.cc
diff --git a/tools/gn/function_forward_variables_from.cc b/tools/gn/function_forward_variables_from.cc
index 8c7a558224e25ea0b21e96b3dff386e37ed8d223..0445f8bd3e2dc64ba5131104cde0fa6fb1cabc9b 100644
--- a/tools/gn/function_forward_variables_from.cc
+++ b/tools/gn/function_forward_variables_from.cc
@@ -172,23 +172,27 @@ Value RunForwardVariablesFrom(Scope* scope,
return Value();
}
- // Extract the scope identifier. This assumes the first parameter is an
- // identifier. It is difficult to write code where this is not the case, and
- // this saves an expensive scope copy. If necessary, this could be expanded
- // to execute the ParseNode and get the value out if it's not an identifer.
+ Value* value = nullptr; // Value to use, may point to result_value.
+ Value result_value; // Storage for the "evaluate" case.
const IdentifierNode* identifier = args_vector[0]->AsIdentifier();
- if (!identifier) {
- *err = Err(args_vector[0].get(), "Expected an identifier for the scope.");
- return Value();
+ if (identifier) {
+ // Optimize the common case where the input scope is an identifier. This
+ // prevents a copy of a potentially large Scope object.
+ value = scope->GetMutableValue(identifier->value().value(),
+ Scope::SEARCH_NESTED, true);
+ if (!value) {
+ *err = Err(identifier, "Undefined identifier.");
+ return Value();
+ }
+ } else {
+ // Non-optimized case, just evaluate the argument.
+ result_value = args_vector[0]->Execute(scope, err);
+ if (err->has_error())
+ return Value();
+ value = &result_value;
}
// Extract the source scope.
- Value* value = scope->GetMutableValue(
- identifier->value().value(), Scope::SEARCH_NESTED, true);
- if (!value) {
- *err = Err(identifier, "Undefined identifier.");
- return Value();
- }
if (!value->VerifyTypeIs(Value::SCOPE, err))
return Value();
Scope* source = value->scope_value();
« no previous file with comments | « tools/gn/format_test_data/067.golden ('k') | tools/gn/function_forward_variables_from_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698