mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: replace sha256 w/ xxhash
This commit is contained in:
@@ -10,8 +10,7 @@ import picocolors from 'picocolors';
|
||||
import createKeywordFilter from './aho-corasick';
|
||||
import { createCacheKey, deserializeArray, fsFetchCache, serializeArray } from './cache-filesystem';
|
||||
import { fastStringArrayJoin } from './misc';
|
||||
|
||||
import { sha256 } from 'hash-wasm';
|
||||
import { stringHash } from './string-hash';
|
||||
|
||||
const BLACK_TLD = new Set([
|
||||
'accountant', 'autos',
|
||||
@@ -114,16 +113,17 @@ export const getPhishingDomains = (parentSpan: Span) => parentSpan.traceChild('g
|
||||
return domainArr;
|
||||
});
|
||||
|
||||
const cacheHash = span.traceChildSync('get hash', () => stringHash(fastStringArrayJoin(domainArr, '|')));
|
||||
|
||||
return span.traceChildAsync(
|
||||
'process phishing domain set',
|
||||
() => processPhihsingDomains(domainArr)
|
||||
() => processPhihsingDomains(domainArr, cacheHash)
|
||||
);
|
||||
});
|
||||
|
||||
async function processPhihsingDomains(domainArr: string[]) {
|
||||
const hash = await sha256(fastStringArrayJoin(domainArr, '|'));
|
||||
async function processPhihsingDomains(domainArr: string[], cacheHash = '') {
|
||||
return fsFetchCache.apply(
|
||||
cacheKey('processPhihsingDomains|' + hash),
|
||||
cacheKey('processPhihsingDomains|' + cacheHash),
|
||||
() => {
|
||||
const domainCountMap: Record<string, number> = {};
|
||||
const domainScoreMap: Record<string, number> = {};
|
||||
|
||||
@@ -48,17 +48,19 @@ export class TextLineStream extends TransformStream<string, string> {
|
||||
}
|
||||
}
|
||||
|
||||
if (lfIndex !== -1) {
|
||||
let crOrLfIndex = lfIndex;
|
||||
if (chunk[lfIndex - 1] === '\r') {
|
||||
crOrLfIndex--;
|
||||
}
|
||||
controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex));
|
||||
chunkIndex = lfIndex + 1;
|
||||
continue;
|
||||
if (lfIndex === -1) {
|
||||
// we can no longer find a line break in the chunk, break the current loop
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
// enqueue current line, and loop again to find next line
|
||||
let crOrLfIndex = lfIndex;
|
||||
if (chunk[lfIndex - 1] === '\r') {
|
||||
crOrLfIndex--;
|
||||
}
|
||||
controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex));
|
||||
chunkIndex = lfIndex + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
__buf = chunk.slice(chunkIndex);
|
||||
|
||||
Reference in New Issue
Block a user