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

Side by Side Diff: tools/gn/value_extractors.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/value.cc ('k') | tools/gn/visibility.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/value_extractors.h" 5 #include "tools/gn/value_extractors.h"
6 6
7 #include "tools/gn/build_settings.h" 7 #include "tools/gn/build_settings.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/label.h" 9 #include "tools/gn/label.h"
10 #include "tools/gn/source_dir.h" 10 #include "tools/gn/source_dir.h"
(...skipping 24 matching lines...) Expand all
35 // there are duplicates. 35 // there are duplicates.
36 template<typename T, class Converter> 36 template<typename T, class Converter>
37 bool ListValueUniqueExtractor(const Value& value, 37 bool ListValueUniqueExtractor(const Value& value,
38 UniqueVector<T>* dest, 38 UniqueVector<T>* dest,
39 Err* err, 39 Err* err,
40 const Converter& converter) { 40 const Converter& converter) {
41 if (!value.VerifyTypeIs(Value::LIST, err)) 41 if (!value.VerifyTypeIs(Value::LIST, err))
42 return false; 42 return false;
43 const std::vector<Value>& input_list = value.list_value(); 43 const std::vector<Value>& input_list = value.list_value();
44 44
45 for (size_t i = 0; i < input_list.size(); i++) { 45 for (const auto& item : input_list) {
46 T new_one; 46 T new_one;
47 if (!converter(input_list[i], &new_one, err)) 47 if (!converter(item, &new_one, err))
48 return false; 48 return false;
49 if (!dest->push_back(new_one)) { 49 if (!dest->push_back(new_one)) {
50 // Already in the list, throw error. 50 // Already in the list, throw error.
51 *err = Err(input_list[i], "Duplicate item in list"); 51 *err = Err(item, "Duplicate item in list");
52 size_t previous_index = dest->IndexOf(new_one); 52 size_t previous_index = dest->IndexOf(new_one);
53 err->AppendSubErr(Err(input_list[previous_index], 53 err->AppendSubErr(Err(input_list[previous_index],
54 "This was the previous definition.")); 54 "This was the previous definition."));
55 return false; 55 return false;
56 } 56 }
57 } 57 }
58 return true; 58 return true;
59 } 59 }
60 60
61 // This extractor rejects files with system-absolute file paths. If we need 61 // This extractor rejects files with system-absolute file paths. If we need
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 } // namespace 137 } // namespace
138 138
139 bool ExtractListOfStringValues(const Value& value, 139 bool ExtractListOfStringValues(const Value& value,
140 std::vector<std::string>* dest, 140 std::vector<std::string>* dest,
141 Err* err) { 141 Err* err) {
142 if (!value.VerifyTypeIs(Value::LIST, err)) 142 if (!value.VerifyTypeIs(Value::LIST, err))
143 return false; 143 return false;
144 const std::vector<Value>& input_list = value.list_value(); 144 const std::vector<Value>& input_list = value.list_value();
145 dest->reserve(input_list.size()); 145 dest->reserve(input_list.size());
146 for (size_t i = 0; i < input_list.size(); i++) { 146 for (const auto& item : input_list) {
147 if (!input_list[i].VerifyTypeIs(Value::STRING, err)) 147 if (!item.VerifyTypeIs(Value::STRING, err))
148 return false; 148 return false;
149 dest->push_back(input_list[i].string_value()); 149 dest->push_back(item.string_value());
150 } 150 }
151 return true; 151 return true;
152 } 152 }
153 153
154 bool ExtractListOfRelativeFiles(const BuildSettings* build_settings, 154 bool ExtractListOfRelativeFiles(const BuildSettings* build_settings,
155 const Value& value, 155 const Value& value,
156 const SourceDir& current_dir, 156 const SourceDir& current_dir,
157 std::vector<SourceFile>* files, 157 std::vector<SourceFile>* files,
158 Err* err) { 158 Err* err) {
159 return ListValueExtractor(value, files, err, 159 return ListValueExtractor(value, files, err,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 210 }
211 211
212 bool ExtractRelativeFile(const BuildSettings* build_settings, 212 bool ExtractRelativeFile(const BuildSettings* build_settings,
213 const Value& value, 213 const Value& value,
214 const SourceDir& current_dir, 214 const SourceDir& current_dir,
215 SourceFile* file, 215 SourceFile* file,
216 Err* err) { 216 Err* err) {
217 RelativeFileConverter converter(build_settings, current_dir); 217 RelativeFileConverter converter(build_settings, current_dir);
218 return converter(value, file, err); 218 return converter(value, file, err);
219 } 219 }
OLDNEW
« no previous file with comments | « tools/gn/value.cc ('k') | tools/gn/visibility.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698