From 213388cd8738bcac2c99a4d20179d6d1cf89d067 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 17 Aug 2023 08:58:04 -0500 Subject: [PATCH] refactor: prefer Sorted variant of MakeFixedFlatSet() (#39537) perf: prefer Sorted variant of MakeFixedFlatSet() https://chromium-review.googlesource.com/c/chromium/src/+/4660000 says that the sorted version is simpler at compile time because it can skip MakeFixedFlatSet()'s compile-time dynamic sorting. --- shell/app/node_main.cc | 15 +++++---- shell/browser/usb/electron_usb_delegate.cc | 2 +- shell/common/node_bindings.cc | 38 +++++++++++++--------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/shell/app/node_main.cc b/shell/app/node_main.cc index 79483e2fae..e03d35cf90 100644 --- a/shell/app/node_main.cc +++ b/shell/app/node_main.cc @@ -54,13 +54,14 @@ namespace { // See https://nodejs.org/api/cli.html#cli_options void ExitIfContainsDisallowedFlags(const std::vector& argv) { // Options that are unilaterally disallowed. - static constexpr auto disallowed = base::MakeFixedFlatSet({ - "--enable-fips", - "--force-fips", - "--openssl-config", - "--use-bundled-ca", - "--use-openssl-ca", - }); + static constexpr auto disallowed = + base::MakeFixedFlatSetSorted({ + "--enable-fips", + "--force-fips", + "--openssl-config", + "--use-bundled-ca", + "--use-openssl-ca", + }); for (const auto& arg : argv) { const auto key = base::StringPiece(arg).substr(0, arg.find('=')); diff --git a/shell/browser/usb/electron_usb_delegate.cc b/shell/browser/usb/electron_usb_delegate.cc index 51711119fd..8bb5726cf5 100644 --- a/shell/browser/usb/electron_usb_delegate.cc +++ b/shell/browser/usb/electron_usb_delegate.cc @@ -45,7 +45,7 @@ electron::UsbChooserContext* GetChooserContext( // These extensions can claim the smart card USB class and automatically gain // permissions for devices that have an interface with this class. constexpr auto kSmartCardPrivilegedExtensionIds = - base::MakeFixedFlatSet({ + base::MakeFixedFlatSetSorted({ // Smart Card Connector Extension and its Beta version, see // crbug.com/1233881. "khpfeaanjngmcnplbdlpegiifgpfgdco", diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 815dbb7d28..4790b00e53 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -232,7 +232,7 @@ void ErrorMessageListener(v8::Local message, // If node CLI inspect support is disabled, allow no debug options. bool IsAllowedOption(base::StringPiece option) { static constexpr auto debug_options = - base::MakeFixedFlatSet({ + base::MakeFixedFlatSetSorted({ "--debug", "--debug-brk", "--debug-port", @@ -244,13 +244,14 @@ bool IsAllowedOption(base::StringPiece option) { }); // This should be aligned with what's possible to set via the process object. - static constexpr auto options = base::MakeFixedFlatSet({ - "--trace-warnings", - "--trace-deprecation", - "--throw-deprecation", - "--no-deprecation", - "--dns-result-order", - }); + static constexpr auto options = + base::MakeFixedFlatSetSorted({ + "--dns-result-order", + "--no-deprecation", + "--throw-deprecation", + "--trace-deprecation", + "--trace-warnings", + }); if (debug_options.contains(option)) return electron::fuses::IsNodeCliInspectEnabled(); @@ -262,14 +263,21 @@ bool IsAllowedOption(base::StringPiece option) { // See https://nodejs.org/api/cli.html#cli_node_options_options void SetNodeOptions(base::Environment* env) { // Options that are unilaterally disallowed - static constexpr auto disallowed = base::MakeFixedFlatSet( - {"--enable-fips", "--force-fips", "--openssl-config", "--use-bundled-ca", - "--use-openssl-ca", "--experimental-policy"}); + static constexpr auto disallowed = + base::MakeFixedFlatSetSorted({ + "--enable-fips", + "--experimental-policy", + "--force-fips", + "--openssl-config", + "--use-bundled-ca", + "--use-openssl-ca", + }); - static constexpr auto pkg_opts = base::MakeFixedFlatSet({ - "--http-parser", - "--max-http-header-size", - }); + static constexpr auto pkg_opts = + base::MakeFixedFlatSetSorted({ + "--http-parser", + "--max-http-header-size", + }); if (env->HasVar("NODE_OPTIONS")) { if (electron::fuses::IsNodeOptionsEnabled()) {