Skip to content

Commit

Permalink
Convert node blacklist to a Set for performance gains
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
husainalzeera committed Dec 4, 2023
1 parent 16401cc commit bd9070c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions platform/node/index.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

var range = require('node-range');

var blacklist = [{{& listSTR }}];
var blacklist = new Set([{{& listSTR }}]);
var isValidEmail = /^{{& unanchoredRegexpString }}$/;

function allDomainSuffixes(email) {
Expand All @@ -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);
Expand All @@ -43,6 +43,6 @@ module.exports = {
return blacklist;
},
addCustomDomains: function (domains = []) {
blacklist.push(...domains)
domains.forEach(item => blacklist.add(item));
}
};

0 comments on commit bd9070c

Please sign in to comment.