Skip to content

Commit

Permalink
fix: clang-tidy performance-inefficient-vector-operation warnings (e…
Browse files Browse the repository at this point in the history
…lectron#44743)

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

* fix: performance-inefficient-vector-operation warning in GetUploadedReports()
  • Loading branch information
ckerr authored Nov 21, 2024
1 parent 6789431 commit 86962ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 11 additions & 11 deletions shell/browser/api/electron_api_crash_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions shell/common/api/electron_api_clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 86962ba

Please sign in to comment.