瀏覽代碼

Perf: make domain sorting faster

SukkaW 1 年之前
父節點
當前提交
db6786a0d6
共有 1 個文件被更改,包括 8 次插入7 次删除
  1. 8 7
      Build/lib/stable-sort-domain.ts

+ 8 - 7
Build/lib/stable-sort-domain.ts

@@ -3,15 +3,16 @@ import { sort } from './timsort';
 
 export const compare = (a: string, b: string) => {
   if (a === b) return 0;
-
-  const aLen = a.length;
-  const r = aLen - b.length;
-  if (r !== 0) return r;
-
-  return a.localeCompare(b);
+  return (a.length - b.length) || a.localeCompare(b);
 };
 
-const tldtsOpt = { allowPrivateDomains: false, detectIp: false, validateHostname: false };
+const tldtsOpt = {
+  extractHostname: false,
+  allowPrivateDomains: false,
+  detectIp: false,
+  validateHostname: false,
+  mixedInputs: false
+};
 
 export const sortDomains = (inputs: string[]) => {
   const domainMap = new Map<string, string>();