mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
const Piscina = require('piscina');
|
|
|
|
const fullsetDomainStartsWithADot = Piscina.workerData
|
|
const totalLen = fullsetDomainStartsWithADot.length;
|
|
|
|
module.exports.dedupe = ({ chunk }) => {
|
|
const chunkLength = chunk.length;
|
|
const outputToBeRemoved = new Int8Array(chunkLength);
|
|
|
|
for (let i = 0; i < chunkLength; i++) {
|
|
const domainFromInput = chunk[i];
|
|
|
|
for (let j = 0; j < totalLen; j++) {
|
|
const domainFromFullSet = fullsetDomainStartsWithADot[j];
|
|
// domainFromFullSet is always startsWith "."
|
|
|
|
if (domainFromFullSet === domainFromInput) continue;
|
|
|
|
const domainFromInputLen = domainFromInput.length;
|
|
const domainFromFullSetLen = domainFromFullSet.length;
|
|
|
|
// !domainFromInput.starsWith('.') && `.${domainFromInput}` === domainFromFullSet
|
|
if (domainFromInput.charCodeAt(0) !== 46) {
|
|
if (domainFromInputLen + 1 === domainFromFullSetLen) {
|
|
|
|
let shouldBeRemoved = true;
|
|
|
|
for (let k = 0; k < domainFromInputLen; k++) {
|
|
if (domainFromFullSet.charCodeAt(k + 1) !== domainFromInput.charCodeAt(k)) {
|
|
shouldBeRemoved = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (shouldBeRemoved) {
|
|
outputToBeRemoved[i] = 1;
|
|
break;
|
|
}
|
|
}
|
|
} else if (domainFromInputLen > domainFromFullSetLen) {
|
|
// domainFromInput is now startsWith a "."
|
|
if (domainFromInput.endsWith(domainFromFullSet)) {
|
|
outputToBeRemoved[i] = 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return Piscina.move(outputToBeRemoved);
|
|
};
|