Repository: electron/electron
Pull request: fix: clang-tidy `performance-inefficient-vector-operation` warnings

#### Description of Change

Fix another couple of `performance-*` warnings generated by clang-tidy. These two [performance-inefficient-vector-operation](https://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html) warnings were basically just "call reserve() before populating the vector":

```
../../electron/shell/browser/api/electron_api_crash_reporter.cc:228:5: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
  227 |   for (auto* const upload : uploads) {
  228 |     result.push_back(gin::DataObjectBuilder(isolate)
      |     ^
../../electron/shell/common/api/electron_api_clipboard.cc:285:5: warning: 'emplace_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
  284 |   for (const auto& file : files) {
  285 |     file_infos.emplace_back(ui::FileInfo(ui::FileInfo(file, file.BaseName())));
      |     ^
```

Fixing them also fixed these other two warnings for free:

```
../../electron/shell/browser/api/electron_api_crash_reporter.cc:227:8: warning: 'auto *const upload' can be declared as 'const auto *const upload' [readability-qualified-auto]
  227 |   for (auto* const upload : uploads) {
      |        ^
      |        const 
../../electron/shell/common/api/electron_api_clipboard.cc:285:29: warning: unnecessary temporary object created while calling emplace_back [modernize-use-emplace]
  285 |     file_infos.emplace_back(ui::FileInfo(ui::FileInfo(file, file.BaseName())));
      |                             ^~~~~~~~~~~~~                                   ~

```

#### Checklist

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: none.

Changed files:
filename: shell/browser/api/electron_api_crash_reporter.cc
patch: @@ -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
 

filename: shell/common/api/electron_api_clipboard.cc
patch: @@ -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));
 }