refactor: use absl::InlinedVector
in ToV8(ElectronPermissionManager)
(#46804)
perf: use a stack-allocated string_view array in ToV8(USBProtectedClasses) 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:
parent
8e5735e499
commit
6433847b09
1 changed files with 4 additions and 3 deletions
|
@ -13,6 +13,8 @@
|
||||||
#include "gin/converter.h"
|
#include "gin/converter.h"
|
||||||
#include "services/device/public/mojom/usb_device.mojom-forward.h"
|
#include "services/device/public/mojom/usb_device.mojom-forward.h"
|
||||||
#include "shell/browser/electron_permission_manager.h"
|
#include "shell/browser/electron_permission_manager.h"
|
||||||
|
#include "shell/common/gin_converters/std_converter.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/inlined_vector.h"
|
||||||
|
|
||||||
namespace gin {
|
namespace gin {
|
||||||
|
|
||||||
|
@ -31,15 +33,14 @@ struct Converter<electron::ElectronPermissionManager::USBProtectedClasses> {
|
||||||
static v8::Local<v8::Value> ToV8(
|
static v8::Local<v8::Value> ToV8(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const electron::ElectronPermissionManager::USBProtectedClasses& classes) {
|
const electron::ElectronPermissionManager::USBProtectedClasses& classes) {
|
||||||
std::vector<std::string> class_strings;
|
absl::InlinedVector<std::string_view, ClassMapping.size()> class_strings;
|
||||||
class_strings.reserve(std::size(classes));
|
|
||||||
for (const auto& itr : classes) {
|
for (const auto& itr : classes) {
|
||||||
for (const auto& [usb_class, name] : ClassMapping) {
|
for (const auto& [usb_class, name] : ClassMapping) {
|
||||||
if (usb_class == itr)
|
if (usb_class == itr)
|
||||||
class_strings.emplace_back(name);
|
class_strings.emplace_back(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return gin::ConvertToV8(isolate, class_strings);
|
return gin::ConvertToV8(isolate, std::span(class_strings));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool FromV8(
|
static bool FromV8(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue