refactor: use Set instead of Array when appropriate (#39324)

This commit is contained in:
Milan Burda 2023-08-03 14:29:57 +02:00 коммит произвёл GitHub
Родитель c5e50e4882
Коммит fe93f69e5a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 7 добавлений и 7 удалений

Просмотреть файл

@ -146,14 +146,14 @@ require('@electron/internal/browser/api/web-frame-main');
// Set main startup script of the app.
const mainStartupScript = packageJson.main || 'index.js';
const KNOWN_XDG_DESKTOP_VALUES = ['Pantheon', 'Unity:Unity7', 'pop:GNOME'];
const KNOWN_XDG_DESKTOP_VALUES = new Set(['Pantheon', 'Unity:Unity7', 'pop:GNOME']);
function currentPlatformSupportsAppIndicator () {
if (process.platform !== 'linux') return false;
const currentDesktop = process.env.XDG_CURRENT_DESKTOP;
if (!currentDesktop) return false;
if (KNOWN_XDG_DESKTOP_VALUES.includes(currentDesktop)) return true;
if (KNOWN_XDG_DESKTOP_VALUES.has(currentDesktop)) return true;
// ubuntu based or derived session (default ubuntu one, communitheme…) supports
// indicator too.
if (/ubuntu/ig.test(currentDesktop)) return true;

Просмотреть файл

@ -26,7 +26,7 @@ const keysOfTypeNumberCompileTimeCheck: { [K in IntegerBrowserWindowOptionKeys]
};
// Note `top` / `left` are special cases from the browser which we later convert
// to y / x.
const keysOfTypeNumber = ['top', 'left', ...Object.keys(keysOfTypeNumberCompileTimeCheck)];
const keysOfTypeNumber = new Set(['top', 'left', ...Object.keys(keysOfTypeNumberCompileTimeCheck)]);
/**
* Note that we only allow "0" and "1" boolean conversion when the type is known
@ -37,7 +37,7 @@ const keysOfTypeNumber = ['top', 'left', ...Object.keys(keysOfTypeNumberCompileT
*/
type CoercedValue = string | number | boolean;
function coerce (key: string, value: string): CoercedValue {
if (keysOfTypeNumber.includes(key)) {
if (keysOfTypeNumber.has(key)) {
return parseInt(value, 10);
}

Просмотреть файл

@ -108,12 +108,12 @@ async function main () {
const onlyTests = args.only && args.only.split(',');
const DISABLED_TESTS = [
const DISABLED_TESTS = new Set([
'nannew-test.js',
'buffer-test.js'
];
]);
const testsToRun = fs.readdirSync(path.resolve(NAN_DIR, 'test', 'js'))
.filter(test => !DISABLED_TESTS.includes(test))
.filter(test => !DISABLED_TESTS.has(test))
.filter(test => {
return !onlyTests || onlyTests.includes(test) || onlyTests.includes(test.replace('.js', '')) || onlyTests.includes(test.replace('-test.js', ''));
})