mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Perf: append large array
This commit is contained in:
parent
16746057e1
commit
1c95540b81
@ -6,6 +6,7 @@ import { task } from './trace';
|
||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import { getPublicSuffixListTextPromise } from './lib/download-publicsuffixlist';
|
||||
import { domainDeduper } from './lib/domain-deduper';
|
||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||
|
||||
const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
|
||||
const trie = createTrie((await getPublicSuffixListTextPromise()).split('\n'));
|
||||
@ -56,7 +57,7 @@ export const buildCdnDownloadConf = task(import.meta.path, async (span) => {
|
||||
readFileIntoProcessedArray(path.resolve(import.meta.dir, '../Source/domainset/steam.conf'))
|
||||
]);
|
||||
|
||||
cdnDomainsList.push(...Array.from(S3OSSDomains).map((domain) => `.${domain}`));
|
||||
appendArrayInPlace(cdnDomainsList, Array.from(S3OSSDomains).map((domain) => `.${domain}`));
|
||||
|
||||
return Promise.all([
|
||||
createRuleset(
|
||||
|
||||
@ -8,6 +8,7 @@ import { isProbablyIpv4, isProbablyIpv6 } from './lib/is-fast-ip';
|
||||
import { TTL, deserializeArray, fsFetchCache, serializeArray } from './lib/cache-filesystem';
|
||||
import { fetchAssets } from './lib/fetch-assets';
|
||||
import { processLine } from './lib/process-line';
|
||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||
|
||||
const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf';
|
||||
|
||||
@ -70,7 +71,8 @@ export const buildRejectIPList = task(import.meta.path, async (span) => {
|
||||
const bogusNxDomainIPs = await span.traceChildPromise('get bogus nxdomain ips', getBogusNxDomainIPsPromise);
|
||||
const botNetIPs = await span.traceChildPromise('get botnet ips', getBotNetFilterIPsPromise);
|
||||
|
||||
result.push(...bogusNxDomainIPs, ...botNetIPs);
|
||||
appendArrayInPlace(result, bogusNxDomainIPs);
|
||||
appendArrayInPlace(result, botNetIPs);
|
||||
|
||||
const description = [
|
||||
...SHARED_DESCRIPTION,
|
||||
|
||||
21
Build/lib/append-array-in-place.ts
Normal file
21
Build/lib/append-array-in-place.ts
Normal file
@ -0,0 +1,21 @@
|
||||
const MAX_BLOCK_SIZE = 65535; // max parameter array size for use in Webkit
|
||||
|
||||
export function appendArrayInPlace<T>(dest: T[], source: T[]) {
|
||||
let offset = 0;
|
||||
let itemsLeft = source.length;
|
||||
|
||||
if (itemsLeft <= MAX_BLOCK_SIZE) {
|
||||
// eslint-disable-next-line prefer-spread -- performance
|
||||
dest.push.apply(dest, source);
|
||||
} else {
|
||||
while (itemsLeft > 0) {
|
||||
const pushCount = Math.min(MAX_BLOCK_SIZE, itemsLeft);
|
||||
const subSource = source.slice(offset, offset + pushCount);
|
||||
// eslint-disable-next-line prefer-spread -- performance
|
||||
dest.push.apply(dest, subSource);
|
||||
itemsLeft -= pushCount;
|
||||
offset += pushCount;
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user