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

Side by Side Diff: tools/gn/input_conversion.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/header_checker.cc ('k') | tools/gn/input_file_manager.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/input_conversion.h" 5 #include "tools/gn/input_conversion.h"
6 6
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "tools/gn/build_settings.h" 9 #include "tools/gn/build_settings.h"
10 #include "tools/gn/err.h" 10 #include "tools/gn/err.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 std::vector<std::string> as_lines; 98 std::vector<std::string> as_lines;
99 base::SplitString(input, '\n', &as_lines); 99 base::SplitString(input, '\n', &as_lines);
100 100
101 // Trim one empty line from the end since the last line might end in a 101 // Trim one empty line from the end since the last line might end in a
102 // newline. If the user wants more trimming, they'll specify "trim" in the 102 // newline. If the user wants more trimming, they'll specify "trim" in the
103 // input conversion options. 103 // input conversion options.
104 if (!as_lines.empty() && as_lines[as_lines.size() - 1].empty()) 104 if (!as_lines.empty() && as_lines[as_lines.size() - 1].empty())
105 as_lines.resize(as_lines.size() - 1); 105 as_lines.resize(as_lines.size() - 1);
106 106
107 ret.list_value().reserve(as_lines.size()); 107 ret.list_value().reserve(as_lines.size());
108 for (size_t i = 0; i < as_lines.size(); i++) 108 for (const auto& line : as_lines)
109 ret.list_value().push_back(Value(origin, as_lines[i])); 109 ret.list_value().push_back(Value(origin, line));
110 return ret; 110 return ret;
111 } 111 }
112 112
113 // Backend for ConvertInputToValue, this takes the extracted string for the 113 // Backend for ConvertInputToValue, this takes the extracted string for the
114 // input conversion so we can recursively call ourselves to handle the optional 114 // input conversion so we can recursively call ourselves to handle the optional
115 // "trim" prefix. This original value is also kept for the purposes of throwing 115 // "trim" prefix. This original value is also kept for the purposes of throwing
116 // errors. 116 // errors.
117 Value DoConvertInputToValue(const Settings* settings, 117 Value DoConvertInputToValue(const Settings* settings,
118 const std::string& input, 118 const std::string& input,
119 const ParseNode* origin, 119 const ParseNode* origin,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 const ParseNode* origin, 208 const ParseNode* origin,
209 const Value& input_conversion_value, 209 const Value& input_conversion_value,
210 Err* err) { 210 Err* err) {
211 if (input_conversion_value.type() == Value::NONE) 211 if (input_conversion_value.type() == Value::NONE)
212 return Value(); // Allow null inputs to mean discard the result. 212 return Value(); // Allow null inputs to mean discard the result.
213 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err)) 213 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err))
214 return Value(); 214 return Value();
215 return DoConvertInputToValue(settings, input, origin, input_conversion_value, 215 return DoConvertInputToValue(settings, input, origin, input_conversion_value,
216 input_conversion_value.string_value(), err); 216 input_conversion_value.string_value(), err);
217 } 217 }
OLDNEW
« no previous file with comments | « tools/gn/header_checker.cc ('k') | tools/gn/input_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698