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

Side by Side Diff: tools/gn/operators.cc

Issue 610293003: Replace more for loops in GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/operators.h" 5 #include "tools/gn/operators.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/parse_tree.h" 9 #include "tools/gn/parse_tree.h"
10 #include "tools/gn/scope.h" 10 #include "tools/gn/scope.h"
(...skipping 18 matching lines...) Expand all
29 dest->list_value().push_back(source); 29 dest->list_value().push_back(source);
30 return; 30 return;
31 } 31 }
32 if (source.type() != Value::LIST) { 32 if (source.type() != Value::LIST) {
33 // Any non-list and non-string being added to a list can just get appended, 33 // Any non-list and non-string being added to a list can just get appended,
34 // we're not going to filter it. 34 // we're not going to filter it.
35 dest->list_value().push_back(source); 35 dest->list_value().push_back(source);
36 return; 36 return;
37 } 37 }
38 38
39 const std::vector<Value>& source_list = source.list_value();
40 if (!filter || filter->is_empty()) { 39 if (!filter || filter->is_empty()) {
41 // No filter, append everything. 40 // No filter, append everything.
42 for (size_t i = 0; i < source_list.size(); i++) 41 for (const auto& source_entry : source.list_value())
43 dest->list_value().push_back(source_list[i]); 42 dest->list_value().push_back(source_entry);
44 return; 43 return;
45 } 44 }
46 45
47 // Note: don't reserve() the dest vector here since that actually hurts 46 // Note: don't reserve() the dest vector here since that actually hurts
48 // the allocation pattern when the build script is doing multiple small 47 // the allocation pattern when the build script is doing multiple small
49 // additions. 48 // additions.
50 for (size_t i = 0; i < source_list.size(); i++) { 49 for (const auto& source_entry : source.list_value()) {
51 if (!filter->MatchesValue(source_list[i])) 50 if (!filter->MatchesValue(source_entry))
52 dest->list_value().push_back(source_list[i]); 51 dest->list_value().push_back(source_entry);
53 } 52 }
54 } 53 }
55 54
56 Value GetValueOrFillError(const BinaryOpNode* op_node, 55 Value GetValueOrFillError(const BinaryOpNode* op_node,
57 const ParseNode* node, 56 const ParseNode* node,
58 const char* name, 57 const char* name,
59 Scope* scope, 58 Scope* scope,
60 Err* err) { 59 Err* err) {
61 Value value = node->Execute(scope, err); 60 Value value = node->Execute(scope, err);
62 if (err->has_error()) 61 if (err->has_error())
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 220
222 // Left-hand-side list. 221 // Left-hand-side list.
223 case Value::LIST: 222 case Value::LIST:
224 switch (right.type()) { 223 switch (right.type()) {
225 case Value::LIST: // list + list -> list concat. 224 case Value::LIST: // list + list -> list concat.
226 if (left_token.value() == kSourcesName) { 225 if (left_token.value() == kSourcesName) {
227 // Filter additions through the assignment filter. 226 // Filter additions through the assignment filter.
228 AppendFilteredSourcesToValue(scope, right, left); 227 AppendFilteredSourcesToValue(scope, right, left);
229 } else { 228 } else {
230 // Normal list concat. 229 // Normal list concat.
231 for (size_t i = 0; i < right.list_value().size(); i++) 230 for (const auto& value : right.list_value())
232 left->list_value().push_back(right.list_value()[i]); 231 left->list_value().push_back(value);
233 } 232 }
234 return; 233 return;
235 234
236 default: 235 default:
237 *err = Err(op_node->op(), "Incompatible types to add.", 236 *err = Err(op_node->op(), "Incompatible types to add.",
238 "To append a single item to a list do \"foo += [ bar ]\"."); 237 "To append a single item to a list do \"foo += [ bar ]\".");
239 return; 238 return;
240 } 239 }
241 240
242 default: 241 default:
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 return ExecuteGreaterEquals(scope, op_node, left_value, right_value, err); 612 return ExecuteGreaterEquals(scope, op_node, left_value, right_value, err);
614 if (op.type() == Token::LESS_EQUAL) 613 if (op.type() == Token::LESS_EQUAL)
615 return ExecuteLessEquals(scope, op_node, left_value, right_value, err); 614 return ExecuteLessEquals(scope, op_node, left_value, right_value, err);
616 if (op.type() == Token::GREATER_THAN) 615 if (op.type() == Token::GREATER_THAN)
617 return ExecuteGreater(scope, op_node, left_value, right_value, err); 616 return ExecuteGreater(scope, op_node, left_value, right_value, err);
618 if (op.type() == Token::LESS_THAN) 617 if (op.type() == Token::LESS_THAN)
619 return ExecuteLess(scope, op_node, left_value, right_value, err); 618 return ExecuteLess(scope, op_node, left_value, right_value, err);
620 619
621 return Value(); 620 return Value();
622 } 621 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698