refactor: apply some 'clang-tidy -fix' changes (#20172)

* refactor: fix clang-tidy vector operation warnings

Fix vector population performance-inefficient-vector-operation warnings
generated by clang-tidy

* refactor: fix clang-tidy emplace_back warnings

In cases where a temporary is created to be passed
to push_back(), replace it with emplace_back().

Warning: modernize-use-emplace

* refactor: fix clang-tidy loop iteration warnings

When practical, use range-based for loops instead of C-style for loops.

clang-tiny check: modernize-loop-convert

* refactor: fix clang-tidy string initialize warning

Remove redundant empty string initialization.

clang-tidy check: readability-redundant-string-init
This commit is contained in:
Charles Kerr 2019-09-13 10:26:59 -04:00 committed by GitHub
parent 3ec17a88ba
commit b2652beceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 62 additions and 69 deletions

View file

@ -751,7 +751,7 @@ base::OnceClosure App::SelectClientCertificate(
// to avoid changes in the API.
auto client_certs = net::CertificateList();
for (const std::unique_ptr<net::ClientCertIdentity>& identity : identities)
client_certs.push_back(identity->certificate());
client_certs.emplace_back(identity->certificate());
auto shared_identities =
std::make_shared<net::ClientCertIdentityList>(std::move(identities));

View file

@ -42,13 +42,13 @@ typename T::iterator FindById(T* container, int id) {
std::vector<std::string> MetricsToArray(uint32_t metrics) {
std::vector<std::string> array;
if (metrics & display::DisplayObserver::DISPLAY_METRIC_BOUNDS)
array.push_back("bounds");
array.emplace_back("bounds");
if (metrics & display::DisplayObserver::DISPLAY_METRIC_WORK_AREA)
array.push_back("workArea");
array.emplace_back("workArea");
if (metrics & display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR)
array.push_back("scaleFactor");
array.emplace_back("scaleFactor");
if (metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION)
array.push_back("rotation");
array.emplace_back("rotation");
return array;
}

View file

@ -248,7 +248,7 @@ struct Converter<electron::api::WebContents::Type> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::WebContents::Type val) {
using Type = electron::api::WebContents::Type;
std::string type = "";
std::string type;
switch (val) {
case Type::BACKGROUND_PAGE:
type = "backgroundPage";
@ -1719,9 +1719,9 @@ void WebContents::Print(mate::Arguments* args) {
std::vector<mate::Dictionary> page_ranges;
if (options.Get("pageRanges", &page_ranges)) {
std::unique_ptr<base::ListValue> page_range_list(new base::ListValue());
for (size_t i = 0; i < page_ranges.size(); ++i) {
for (auto& range : page_ranges) {
int from, to;
if (page_ranges[i].Get("from", &from) && page_ranges[i].Get("to", &to)) {
if (range.Get("from", &from) && range.Get("to", &to)) {
std::unique_ptr<base::DictionaryValue> range(
new base::DictionaryValue());
range->SetInteger(printing::kSettingPageRangeFrom, from);