mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: minor optimization here and there
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user