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

Unified Diff: tools/gn/function_foreach.cc

Issue 2095043005: Add GN split_list function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 6 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/BUILD.gn ('k') | tools/gn/functions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_foreach.cc
diff --git a/tools/gn/function_foreach.cc b/tools/gn/function_foreach.cc
index b74fc186af115c95ad951c7bd2c5389ba6ce4697..d8fe87ed8c61be19638b688f137359bbfae5357e 100644
--- a/tools/gn/function_foreach.cc
+++ b/tools/gn/function_foreach.cc
@@ -4,6 +4,7 @@
#include "tools/gn/err.h"
#include "tools/gn/functions.h"
+#include "tools/gn/parse_node_value_adapter.h"
#include "tools/gn/parse_tree.h"
#include "tools/gn/scope.h"
@@ -63,27 +64,11 @@ Value RunForEach(Scope* scope,
}
base::StringPiece loop_var(identifier->value().value());
- // Extract the list, avoid a copy if it's an identifier (common case).
- Value value_storage_for_exec; // Backing for list_value when we need to exec.
- const Value* list_value = nullptr;
- const IdentifierNode* list_identifier = args_vector[1]->AsIdentifier();
- if (list_identifier) {
- list_value = scope->GetValue(list_identifier->value().value(), true);
- if (!list_value) {
- *err = Err(args_vector[1].get(), "Undefined identifier.");
- return Value();
- }
- } else {
- // Not an identifier, evaluate the node to get the result.
- Scope list_exec_scope(scope);
- value_storage_for_exec = args_vector[1]->Execute(scope, err);
- if (err->has_error())
- return Value();
- list_value = &value_storage_for_exec;
- }
- if (!list_value->VerifyTypeIs(Value::LIST, err))
+ // Extract the list to iterate over.
+ ParseNodeValueAdapter list_adapter;
+ if (!list_adapter.InitForType(scope, args_vector[1].get(), Value::LIST, err))
return Value();
- const std::vector<Value>& list = list_value->list_value();
+ const std::vector<Value>& list = list_adapter.get().list_value();
// Block to execute.
const BlockNode* block = function->block();
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/functions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698