瀏覽代碼

Perf: limit split when parsing hosts

SukkaW 1 年之前
父節點
當前提交
b1912c89ac
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      Build/lib/parse-filter/hosts.ts

+ 3 - 1
Build/lib/parse-filter/hosts.ts

@@ -3,8 +3,10 @@ import { fetchAssets } from '../fetch-assets';
 import { fastNormalizeDomainWithoutWww } from '../normalize-domain';
 import { fastNormalizeDomainWithoutWww } from '../normalize-domain';
 import { onBlackFound } from './shared';
 import { onBlackFound } from './shared';
 
 
+const rSpace = /\s+/;
+
 function hostsLineCb(line: string, set: string[], includeAllSubDomain: boolean, meta: string) {
 function hostsLineCb(line: string, set: string[], includeAllSubDomain: boolean, meta: string) {
-  const _domain = line.split(/\s/)[1]?.trim();
+  const _domain = line.split(rSpace, 3)[1]?.trim();
   if (!_domain) {
   if (!_domain) {
     return;
     return;
   }
   }