fix: clang-tidy performance-inefficient-vector-operation warnings (#44775)

* fix: performance-inefficient-vector-operation warning in Clipboard::WriteFilesForTesting()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fix: performance-inefficient-vector-operation warning in GetUploadedReports()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-11-21 14:30:45 -05:00 committed by GitHub
parent 19e6ca921f
commit 787d4c3859
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 16 deletions

View file

@ -10,6 +10,7 @@
#include <utility>
#include <vector>
#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<v8::Value> 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<size_t>::max();
const std::vector<const UploadList::UploadInfo*> uploads =
list->GetUploads(kMaxUploadReportsToList);
std::vector<v8::Local<v8::Object>> 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::Value> v8_result = gin::ConvertToV8(isolate, result);
return v8_result;
return gin::ConvertToV8(
isolate,
base::ToVector(list->GetUploads(kMaxUploadReportsToList), to_obj));
}
#endif

View file

@ -7,6 +7,7 @@
#include <map>
#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<base::FilePath>& files) {
std::vector<ui::FileInfo> 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));
}