Merge pull request #11726 from electron/faster-compare-blacklist

Make use of sorted list to speed up searching
This commit is contained in:
shelley vohr 2018-01-30 09:46:38 -05:00 committed by GitHub
commit f24eab74d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,10 +2,11 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include <string>
#include "atom/app/command_line_args.h"
#include <algorithm>
#include <string>
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_switches.h"
@ -37,18 +38,36 @@ bool IsUrlArg(const base::CommandLine::CharType* arg) {
return false;
}
const char* blacklist[] = {
// node
"inspect",
"inspect-brk",
// chromium switches:
// find ./ -name "*switches.cc" \
// | xargs grep -P --no-filename "\"\S+\";" \
// | perl -pe 's|^.*?"(\S+)";| "$1",|' \
// | sort | uniq
"?",
// The blacklist of command line switches, must be sorted.
// Created with:
// find ./ -name "*switches.cc" \
// | xargs grep -P --no-filename "\"\S+\";" \
// | perl -pe 's|^.*?"(\S+)";| "$1",|' \
// | sort | uniq
// then manually insert following switches into the list:
// "inspect",
// "inspect-brk",
// finally write a small piece of code to print out the sorted list since
// the "sort" tool may use differnt rules from C++ STL.
// std::vector<std::string> sorted(std::begin(kBlacklist),
// std::end(kBlacklist));
// std::sort(sorted.begin(), sorted.end());
// FILE* f = fopen("testlist2", "w+");
// for (auto& i : sorted)
// fprintf(f, "\"%s\",\n", i.c_str());
// fclose(f);
const char* kBlacklist[] = {
"/prefetch:1",
"/prefetch:2",
"/prefetch:3",
"/prefetch:4",
"/prefetch:5",
"/prefetch:6",
"/prefetch:8",
"0",
"?",
"ChromeOSMemoryPressureHandling",
"SafeSites",
"accept-resource-provider",
"account-consistency",
"adaboost",
@ -58,6 +77,7 @@ const char* blacklist[] = {
"aggressive-cache-discard",
"aggressive-tab-discard",
"all",
"all-toolchains",
"allarticles",
"allow-cross-origin-auth-prompt",
"allow-external-pages",
@ -78,7 +98,6 @@ const char* blacklist[] = {
"allow-running-insecure-content",
"allow-sandbox-debugging",
"allow-silent-push",
"all-toolchains",
"alsa-check-close-timeout",
"alsa-enable-upsampling",
"alsa-fixed-output-sample-rate",
@ -96,8 +115,8 @@ const char* blacklist[] = {
"alternative",
"always-authorize-plugins",
"always-on",
"alwaystrue",
"always-use-complex-text",
"alwaystrue",
"amd-switchable",
"android-fonts-path",
"android-stderr-port",
@ -107,18 +126,18 @@ const char* blacklist[] = {
"app",
"app-auto-launched",
"app-id",
"apple",
"app-mode-auth-code",
"app-mode-oauth-token",
"app-mode-oem-manifest",
"apps-gallery-download-url",
"apps-gallery-update-url",
"apps-gallery-url",
"app-shell-allow-roaming",
"app-shell-host-window-size",
"app-shell-preferred-network",
"app-shell-refresh-token",
"app-shell-user",
"apple",
"apps-gallery-download-url",
"apps-gallery-update-url",
"apps-gallery-url",
"apps-keep-chrome-alive-in-tests",
"arc-availability",
"arc-available",
@ -155,8 +174,8 @@ const char* blacklist[] = {
"auth-spnego-account-type",
"auto",
"auto-open-devtools-for-tabs",
"autoplay-policy",
"auto-select-desktop-capture-source",
"autoplay-policy",
"blink-settings",
"bootstrap",
"browser",
@ -178,7 +197,6 @@ const char* blacklist[] = {
"child-wallpaper-large",
"child-wallpaper-small",
"chrome-home-swipe-logic",
"ChromeOSMemoryPressureHandling",
"cipher-suite-blacklist",
"clamshell",
"class",
@ -202,21 +220,21 @@ const char* blacklist[] = {
"crash-dumps-dir",
"crash-on-failure",
"crash-on-hang-threads",
"crashpad-handler",
"crash-server-url",
"crash-test",
"crashpad-handler",
"create-browser-on-startup-for-tests",
"cros-gaia-api-v1",
"crosh-command",
"cros-region",
"cros-regions-mode",
"crosh-command",
"cryptauth-http-host",
"custom-devtools-frontend",
"custom-launcher-page",
"custom_summary",
"d3d-support",
"d3d11",
"d3d9",
"d3d-support",
"daemon",
"dark_muted",
"dark_vibrant",
@ -262,17 +280,17 @@ const char* blacklist[] = {
"disable-accelerated-jpeg-decoding",
"disable-accelerated-mjpeg-decode",
"disable-accelerated-video-decode",
"disable-appcontainer",
"disable-app-info-dialog-mac",
"disable-app-list-dismiss-on-blur",
"disable-app-window-cycling",
"disable-appcontainer",
"disable-arc-data-wipe",
"disable-arc-opt-in-verification",
"disable-audio-support-for-desktop-share",
"disable-avfoundation-overlays",
"disable-backgrounding-occluded-windows",
"disable-background-networking",
"disable-background-timer-throttling",
"disable-backgrounding-occluded-windows",
"disable-backing-store-limit",
"disable-blink-features",
"disable-boot-animation",
@ -291,7 +309,6 @@ const char* blacklist[] = {
"disable-component-update",
"disable-composited-antialiasing",
"disable-contextual-search",
"disabled",
"disable-d3d11",
"disable-databases",
"disable-datasaver-prompt",
@ -305,7 +322,6 @@ const char* blacklist[] = {
"disable-directwrite-for-ui",
"disable-display-list-2d-canvas",
"disable-distance-field-text",
"disabled-new-style-notification",
"disable-domain-blocking-for-3d-apis",
"disable-domain-reliability",
"disable-drive-search-in-app-launcher",
@ -352,8 +368,8 @@ const char* blacklist[] = {
"disable-histogram-customizer",
"disable-hosted-app-shim-creation",
"disable-hosted-apps-in-windows",
"disable-infobars",
"disable-in-process-stack-traces",
"disable-infobars",
"disable-input-ime-api",
"disable-input-view",
"disable-ios-password-suggestions",
@ -370,9 +386,9 @@ const char* blacklist[] = {
"disable-low-end-device-mode",
"disable-low-latency-dxva",
"disable-low-res-tiling",
"disable-machine-cert-request",
"disable-mac-overlays",
"disable-mac-views-native-app-windows",
"disable-machine-cert-request",
"disable-main-frame-before-activation",
"disable-md-error-screen",
"disable-md-oobe",
@ -405,9 +421,9 @@ const char* blacklist[] = {
"disable-password-generation",
"disable-pepper-3d",
"disable-pepper-3d-image-chromium",
"disable-per-user-timezone",
"disable-permission-action-reporting",
"disable-permissions-api",
"disable-per-user-timezone",
"disable-physical-keyboard-autocorrect",
"disable-pinch",
"disable-pnacl-crash-throttling",
@ -439,8 +455,8 @@ const char* blacklist[] = {
"disable-signin-scoped-device-id",
"disable-single-click-autofill",
"disable-skia-runtime-opts",
"disable-slimming-paint-invalidation",
"disable-slim-navigation-manager",
"disable-slimming-paint-invalidation",
"disable-smooth-scrolling",
"disable-software-rasterizer",
"disable-speech-api",
@ -466,18 +482,20 @@ const char* blacklist[] = {
"disable-voice-input",
"disable-volume-adjust-sound",
"disable-wake-on-wifi",
"disable-web-notification-custom-layouts",
"disable-web-security",
"disable-webgl",
"disable-webgl-image-chromium",
"disable-web-notification-custom-layouts",
"disable-webrtc-encryption",
"disable-webrtc-hw-decoding",
"disable-webrtc-hw-encoding",
"disable-web-security",
"disable-win32k-lockdown",
"disable-xss-auditor",
"disable-zero-browsers-open-for-tests",
"disable-zero-copy",
"disable-zero-copy-dxgi-video",
"disabled",
"disabled-new-style-notification",
"disallow-non-exact-resource-reuse",
"disk-cache-dir",
"disk-cache-size",
@ -508,10 +526,10 @@ const char* blacklist[] = {
"enable-adaptive-selection-handle-orientation",
"enable-aggressive-domstorage-flushing",
"enable-android-wallpapers-app",
"enable-appcontainer",
"enable-app-info-dialog-mac",
"enable-app-list",
"enable-app-window-cycling",
"enable-appcontainer",
"enable-arc",
"enable-arc-oobe-optin",
"enable-async-event-targeting",
@ -536,9 +554,6 @@ const char* blacklist[] = {
"enable-crash-reporter",
"enable-crash-reporter-for-testing",
"enable-crx-hash-check",
"enabled",
"enabled-2g",
"enabled-3g",
"enable-data-reduction-proxy-bypass-warning",
"enable-data-reduction-proxy-force-pingback",
"enable-data-reduction-proxy-lite-page",
@ -550,12 +565,10 @@ const char* blacklist[] = {
"enable-display-list-2d-canvas",
"enable-distance-field-text",
"enable-distillability-service",
"enabled-new-style-notification",
"enable-domain-reliability",
"enable-dom-distiller",
"enable-domain-reliability",
"enable-drive-search-in-app-launcher",
"enable-drm-atomic",
"enabled-slow2g",
"enable-embedded-extension-options",
"enable-encryption-migration",
"enable-encryption-selection",
@ -567,8 +580,8 @@ const char* blacklist[] = {
"enable-experimental-fullscreen-exit-ui",
"enable-experimental-input-view-features",
"enable-experimental-web-platform-features",
"enable-extension-activity-logging",
"enable-extension-activity-log-testing",
"enable-extension-activity-logging",
"enable-extension-assets-sharing",
"enable-external-drive-rename",
"enable-fast-unload",
@ -672,9 +685,9 @@ const char* blacklist[] = {
"enable-single-click-autofill",
"enable-site-settings",
"enable-skia-benchmarking",
"enable-slim-navigation-manager",
"enable-slimming-paint-invalidation",
"enable-slimming-paint-v2",
"enable-slim-navigation-manager",
"enable-smooth-scrolling",
"enable-spatial-navigation",
"enable-spdy-proxy-auth",
@ -708,9 +721,9 @@ const char* blacklist[] = {
"enable-tracing-output",
"enable-translate-new-ux",
"enable-ui-devtools",
"enable-usermedia-screen-capturing",
"enable-user-metrics",
"enable-use-zoom-for-dsf",
"enable-user-metrics",
"enable-usermedia-screen-capturing",
"enable-video-player-chromecast-support",
"enable-viewport",
"enable-virtual-keyboard",
@ -718,11 +731,11 @@ const char* blacklist[] = {
"enable-vtune-support",
"enable-vulkan",
"enable-wayland-server",
"enable-web-notification-custom-layouts",
"enable-webfonts-intervention-trigger",
"enable-webfonts-intervention-v2",
"enable-webgl-draft-extensions",
"enable-webgl-image-chromium",
"enable-web-notification-custom-layouts",
"enable-webrtc-event-logging-from-extension",
"enable-webrtc-srtp-aes-gcm",
"enable-webrtc-srtp-encrypted-headers",
@ -733,11 +746,16 @@ const char* blacklist[] = {
"enable-win7-webrtc-hw-h264-decoding",
"enable-zero-copy",
"enable-zip-archiver-on-file-manager",
"enabled",
"enabled-2g",
"enabled-3g",
"enabled-new-style-notification",
"enabled-slow2g",
"encode-binary",
"enforce",
"enforce-gl-minimums",
"enforce_strict",
"enforce-webrtc-ip-permission-check",
"enforce_strict",
"enterprise-disable-arc",
"enterprise-enable-forced-re-enrollment",
"enterprise-enable-license-type-selection",
@ -745,8 +763,8 @@ const char* blacklist[] = {
"enterprise-enrollment-initial-modulus",
"enterprise-enrollment-modulus-limit",
"error-console",
"evaluate_capability",
"evaluate-type",
"evaluate_capability",
"experiment",
"explicitly-allowed-ports",
"expose-internals-for-testing",
@ -774,8 +792,8 @@ const char* blacklist[] = {
"force-clamshell-power-button",
"force-color-profile",
"force-desktop-ios-promotion",
"force-device-scale-factor",
"force-dev-mode-highlighting",
"force-device-scale-factor",
"force-display-list-2d-canvas",
"force-effective-connection-type",
"force-enable-metrics-reporting",
@ -814,8 +832,8 @@ const char* blacklist[] = {
"generate-accessibility-test-expectations",
"gl",
"gl-composited-overlay-candidate-quad-border",
"gles",
"gl-shader-interm-output",
"gles",
"golden-screenshots-dir",
"google-apis-url",
"google-base-url",
@ -875,9 +893,11 @@ const char* blacklist[] = {
"ignore-gpu-blacklist",
"ignore-urlfetcher-cert-requests",
"ignore-user-profile-mapping-for-tests",
"incognito",
"in-process-gpu",
"incognito",
"input",
"inspect",
"inspect-brk",
"install-chrome-app",
"install-supervised-user-whitelists",
"instant-process",
@ -885,9 +905,9 @@ const char* blacklist[] = {
"ipc-connection-timeout",
"ipc-dump-directory",
"ipc-fuzzer-testcase",
"is-running-in-mash",
"isolate-origins",
"isolate-sites-for-testing",
"is-running-in-mash",
"javascript-harmony",
"js-flags",
"keep-alive-for-test",
@ -907,11 +927,11 @@ const char* blacklist[] = {
"local-ntp-reload",
"local-sync-backend-dir",
"log-gpu-control-list-decisions",
"log-level",
"log-net-log",
"login-manager",
"login-profile",
"login-user",
"log-level",
"log-net-log",
"loopback-i2s-bits",
"loopback-i2s-bus-name",
"loopback-i2s-channels",
@ -923,9 +943,9 @@ const char* blacklist[] = {
"make-default-browser",
"managed-user-id",
"managed-user-sync-token",
"mark-non-secure-as",
"markdown",
"market-url-for-testing",
"mark-non-secure-as",
"mash",
"material",
"material-design-ink-drop-animation-speed",
@ -935,11 +955,11 @@ const char* blacklist[] = {
"max-untiled-layer-height",
"max-untiled-layer-width",
"media-cache-size",
"mem-pressure-system-reserved-kb",
"memlog",
"memory-pressure-off",
"memory-pressure-thresholds",
"memory-pressure-thresholds-mb",
"mem-pressure-system-reserved-kb",
"message-center-changes-while-open",
"method",
"metrics-client-id",
@ -965,37 +985,37 @@ const char* blacklist[] = {
"native",
"native-crx-bindings",
"need-arc-migration-policy-check",
"netifs-to-ignore",
"net-log-capture-mode",
"netifs-to-ignore",
"network-country-iso",
"network-settings-config",
"new-window",
"nocolor",
"no-default-browser-check",
"noerrdialogs",
"no-experiments",
"no-first-run",
"no-managed-user-acknowledgment-check",
"none",
"no-network-profile-warning",
"no-pings",
"no-proxy-server",
"no-referrers",
"no-sandbox",
"no-service-autorun",
"no-session-id",
"no-startup-window",
"no-user-gesture-required",
"no-wifi",
"no-zygote",
"nocolor",
"noerrdialogs",
"non-material",
"non-secure",
"non-secure-after-editing",
"non-secure-while-incognito",
"non-secure-while-incognito-or-editing",
"no-pings",
"no-proxy-server",
"no-referrers",
"none",
"normal_muted",
"normal_vibrant",
"no-sandbox",
"no-service-autorun",
"no-session-id",
"no-startup-window",
"note-taking-app-ids",
"no-user-gesture-required",
"no-wifi",
"no-zygote",
"ntp-snippets-add-incomplete",
"null",
"num-raster-threads",
@ -1010,10 +1030,10 @@ const char* blacklist[] = {
"oobe-timer-interval",
"open-ash",
"opengraph",
"original-process-start-time",
"origin-trial-disabled-features",
"origin-trial-disabled-tokens",
"origin-trial-public-key",
"original-process-start-time",
"osmesa",
"output",
"override",
@ -1042,13 +1062,6 @@ const char* blacklist[] = {
"ppapi-plugin-launcher",
"ppapi-startup-dialog",
"ppapi-subpixel-rendering-setting",
"/prefetch:1",
"/prefetch:2",
"/prefetch:3",
"/prefetch:4",
"/prefetch:5",
"/prefetch:6",
"/prefetch:8",
"previous-app",
"primary",
"print-to-pdf",
@ -1075,8 +1088,8 @@ const char* blacklist[] = {
"reader-mode-heuristics",
"rebaseline-pixel-tests",
"record-type",
"reduced-referrer-granularity",
"reduce-security-for-testing",
"reduced-referrer-granularity",
"register-font-files",
"register-pepper-plugins",
"relauncher",
@ -1108,7 +1121,6 @@ const char* blacklist[] = {
"safebrowsing-disable-download-protection",
"safebrowsing-disable-extension-blacklist",
"safebrowsing-manual-download-blacklist",
"SafeSites",
"sandbox-ipc",
"save-page-as-mhtml",
"screen-config",
@ -1178,10 +1190,10 @@ const char* blacklist[] = {
"ssl-version-max",
"ssl-version-min",
"stable-release-mode",
"started",
"start-fullscreen",
"start-maximized",
"start-stack-profiler",
"started",
"stub",
"stub-cros-settings",
"surface",
@ -1209,8 +1221,6 @@ const char* blacklist[] = {
"test-do-not-initialize-icu",
"test-encryption-migration-ui",
"test-gl-lib",
"testing-fixed-http-port",
"testing-fixed-https-port",
"test-launcher-batch-limit",
"test-launcher-bot-mode",
"test-launcher-debug-launcher",
@ -1231,6 +1241,8 @@ const char* blacklist[] = {
"test-name",
"test-tiny-timeout",
"test-type",
"testing-fixed-http-port",
"testing-fixed-https-port",
"tether-stub",
"third-party-doodle-url",
"threads",
@ -1252,7 +1264,6 @@ const char* blacklist[] = {
"touch_view",
"trace-config-file",
"trace-export-events-to-etw",
"tracelog",
"trace-shutdown",
"trace-shutdown-file",
"trace-startup",
@ -1262,6 +1273,7 @@ const char* blacklist[] = {
"trace-to-file",
"trace-to-file-name",
"trace-upload-url",
"tracelog",
"translate-ranker-model-url",
"translate-script-url",
"translate-security-origin",
@ -1287,9 +1299,9 @@ const char* blacklist[] = {
"ui-test-action-timeout",
"uninstall",
"unlimited-storage",
"unsafe-pac-url",
"unsafely-allow-protected-media-identifier-for-domain",
"unsafely-treat-insecure-origin-as-secure",
"unsafe-pac-url",
"use-angle",
"use-cras",
"use-fake-device-for-media-stream",
@ -1304,15 +1316,15 @@ const char* blacklist[] = {
"use-mobile-user-agent",
"use-mock-keychain",
"use-passthrough-cmd-decoder",
"use-skia-renderer",
"use-system-default-printer",
"use-test-config",
"use-viz-hit-test",
"user-agent",
"user-always-affiliated",
"user-data-dir",
"user-gesture-required",
"user-gesture-required-for-cross-origin",
"use-skia-renderer",
"use-system-default-printer",
"use-test-config",
"use-viz-hit-test",
"utility",
"utility-allowed-dir",
"utility-cmd-prefix",
@ -1346,16 +1358,16 @@ const char* blacklist[] = {
"webview-enable-safebrowsing-support",
"webview-sandboxed-renderer",
"whitelisted-extension-id",
"win-jumplist-action",
"window-position",
"windows10-custom-titlebar",
"window-size",
"window-workspace",
"windows10-custom-titlebar",
"winhttp-proxy-resolver",
"win-jumplist-action",
"wm-window-animations-disabled",
"yield-between-content-script-runs",
"zygote",
"zygote-cmd-prefix"
"zygote-cmd-prefix",
};
bool IsBlacklistedArg(const base::CommandLine::CharType* arg) {
@ -1379,9 +1391,10 @@ bool IsBlacklistedArg(const base::CommandLine::CharType* arg) {
if (prefix_length > 0) {
a += prefix_length;
std::string switch_name(a, strcspn(a, "="));
for (auto& item : blacklist) {
if (switch_name == item)
return true;
auto* iter = std::lower_bound(std::begin(kBlacklist), std::end(kBlacklist),
switch_name);
if (iter != std::end(kBlacklist) && switch_name == *iter) {
return true;
}
}
@ -1393,6 +1406,16 @@ bool IsBlacklistedArg(const base::CommandLine::CharType* arg) {
namespace atom {
bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
DCHECK(std::is_sorted(std::begin(kBlacklist), std::end(kBlacklist),
[](const char* a, const char* b) {
return base::StringPiece(a) < base::StringPiece(b);
}))
<< "The kBlacklist must be in sorted order";
DCHECK_NE(std::find(std::begin(kBlacklist), std::end(kBlacklist),
base::StringPiece("inspect")),
std::end(kBlacklist))
<< "Do not forget to add Node command line flags to kBlacklist";
const base::CommandLine::StringType dashdash(2, '-');
bool block_blacklisted_args = false;
for (int i = 0; i < argc; ++i) {