From bd9070cdce1c45cf2769e2b5c66db44d14725f7e Mon Sep 17 00:00:00 2001 From: husainalzeera <99366227+husainalzeera@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:30:32 -0800 Subject: [PATCH] Convert node blacklist to a Set for performance gains The node code is currently going through the blacklist array through an `indexOf` call. By converting it to a Set and using `has` there is a significant performance gain. --- platform/node/index.tmpl.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/node/index.tmpl.js b/platform/node/index.tmpl.js index ac058e2e..b37f55fd 100644 --- a/platform/node/index.tmpl.js +++ b/platform/node/index.tmpl.js @@ -9,7 +9,7 @@ var range = require('node-range'); -var blacklist = [{{& listSTR }}]; +var blacklist = new Set([{{& listSTR }}]); var isValidEmail = /^{{& unanchoredRegexpString }}$/; function allDomainSuffixes(email) { @@ -22,7 +22,7 @@ function allDomainSuffixes(email) { function isBlacklisted(email) { function suffixIsBlacklisted(domainSuffix) { - return blacklist.indexOf(domainSuffix) >= 0; + return blacklist.has(domainSuffix); } return allDomainSuffixes(email).some(suffixIsBlacklisted); @@ -43,6 +43,6 @@ module.exports = { return blacklist; }, addCustomDomains: function (domains = []) { - blacklist.push(...domains) + domains.forEach(item => blacklist.add(item)); } };