From ffa4e03d0868efdb1bc741563f194e7517834fa4 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 18 Jan 2025 01:35:25 +0800 Subject: [PATCH] Perf: make `fileEqual` faster --- Build/lib/rules/base.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Build/lib/rules/base.ts b/Build/lib/rules/base.ts index d2e66050..1f74712a 100644 --- a/Build/lib/rules/base.ts +++ b/Build/lib/rules/base.ts @@ -401,6 +401,10 @@ export async function fileEqual(linesA: string[], source: AsyncIterable const firstCharA = lineA.charCodeAt(0); const firstCharB = lineB.charCodeAt(0); + if (firstCharA !== firstCharB) { + return false; + } + if (firstCharA === 35 /* # */ && firstCharB === 35 /* # */) { continue; } @@ -410,13 +414,9 @@ export async function fileEqual(linesA: string[], source: AsyncIterable } if ( - firstCharA === 47 /* / */ - && firstCharB === 47 /* / */ - - && lineA[1] === '/' - && lineB[1] === '/' - && lineA[3] === '#' - && lineB[3] === '#' + firstCharA === 47 /* / */ && firstCharB === 47 /* / */ + && lineA[1] === '/' && lineB[1] === '/' + && lineA[3] === '#' && lineB[3] === '#' ) { continue; }