Perf: minor optimization here and there

This commit is contained in:
SukkaW
2024-01-11 11:56:15 +08:00
parent d06fa6975d
commit e8f3519479
11 changed files with 80 additions and 60 deletions

View File

@@ -10,8 +10,16 @@ export const normalizeDomain = (domain: string) => {
if (!parsed.isIcann && !parsed.isPrivate) return null;
let h = parsed.hostname;
if (h[0] === '.') h = h.slice(1);
if (h.endsWith('.')) h = h.slice(0, -1);
let sliceStart = 0;
let sliceEnd = h.length;
if (h[0] === '.') sliceStart = 1;
if (h.endsWith('.')) sliceEnd = -1;
if (sliceStart !== 0 || sliceEnd !== h.length) {
h = h.slice(sliceStart, sliceEnd);
}
if (h) return h;
return null;