From 787d4c385918a30c591a29de18474f9b0261813d Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:30:45 -0500 Subject: [PATCH] fix: clang-tidy `performance-inefficient-vector-operation` warnings (#44775) * fix: performance-inefficient-vector-operation warning in Clipboard::WriteFilesForTesting() Co-authored-by: Charles Kerr * fix: performance-inefficient-vector-operation warning in GetUploadedReports() Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- .../api/electron_api_crash_reporter.cc | 22 +++++++++---------- shell/common/api/electron_api_clipboard.cc | 8 +++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/shell/browser/api/electron_api_crash_reporter.cc b/shell/browser/api/electron_api_crash_reporter.cc index 1e1dbedcc277..c10e47307af8 100644 --- a/shell/browser/api/electron_api_crash_reporter.cc +++ b/shell/browser/api/electron_api_crash_reporter.cc @@ -10,6 +10,7 @@ #include #include +#include "base/containers/to_vector.h" #include "base/no_destructor.h" #include "base/path_service.h" #include "base/strings/utf_string_conversions.h" @@ -220,18 +221,17 @@ v8::Local GetUploadedReports(v8::Isolate* isolate) { list->LoadSync(); } + auto to_obj = [isolate](const UploadList::UploadInfo* upload) { + return gin::DataObjectBuilder{isolate} + .Set("date", upload->upload_time) + .Set("id", upload->upload_id) + .Build(); + }; + constexpr size_t kMaxUploadReportsToList = std::numeric_limits::max(); - const std::vector uploads = - list->GetUploads(kMaxUploadReportsToList); - std::vector> result; - for (auto* const upload : uploads) { - result.push_back(gin::DataObjectBuilder(isolate) - .Set("date", upload->upload_time) - .Set("id", upload->upload_id) - .Build()); - } - v8::Local v8_result = gin::ConvertToV8(isolate, result); - return v8_result; + return gin::ConvertToV8( + isolate, + base::ToVector(list->GetUploads(kMaxUploadReportsToList), to_obj)); } #endif diff --git a/shell/common/api/electron_api_clipboard.cc b/shell/common/api/electron_api_clipboard.cc index 72d816bea855..87b5f4d3be1e 100644 --- a/shell/common/api/electron_api_clipboard.cc +++ b/shell/common/api/electron_api_clipboard.cc @@ -7,6 +7,7 @@ #include #include "base/containers/contains.h" +#include "base/containers/to_vector.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "shell/browser/browser.h" @@ -280,11 +281,8 @@ void Clipboard::Clear(gin_helper::Arguments* args) { // This exists for testing purposes ONLY. void Clipboard::WriteFilesForTesting(const std::vector& files) { - std::vector file_infos; - for (const auto& file : files) { - file_infos.emplace_back(ui::FileInfo(ui::FileInfo(file, file.BaseName()))); - } - + auto to_info = [](const auto& p) { return ui::FileInfo{p, p.BaseName()}; }; + auto file_infos = base::ToVector(files, to_info); ui::ScopedClipboardWriter writer(ui::ClipboardBuffer::kCopyPaste); writer.WriteFilenames(ui::FileInfosToURIList(file_infos)); }