From 3952e27d644623ab3dd3e940752a7fda07e5d2c3 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 23 Feb 2025 22:32:11 +0800 Subject: [PATCH] Perf: improve file comparision --- Build/lib/create-file.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Build/lib/create-file.ts b/Build/lib/create-file.ts index 8fda87b3..3beed226 100644 --- a/Build/lib/create-file.ts +++ b/Build/lib/create-file.ts @@ -14,6 +14,10 @@ export async function fileEqual(linesA: string[], source: AsyncIterable const linesABound = linesA.length - 1; let index = -1; + + let aLen = 0; + let bLen = 0; + for await (const lineB of source) { index++; @@ -22,9 +26,11 @@ export async function fileEqual(linesA: string[], source: AsyncIterable } const lineA = linesA[index]; + aLen = lineA.length; + bLen = lineB.length; - if (lineA.length === 0) { - if (lineB.length === 0) { + if (aLen === 0) { + if (bLen === 0) { // both lines are empty, check next line continue; } @@ -32,7 +38,7 @@ export async function fileEqual(linesA: string[], source: AsyncIterable return false; } // now lineA can not be empty - if (lineB.length === 0) { + if (bLen === 0) { // lineB is empty but lineA is not return false; } @@ -63,6 +69,10 @@ export async function fileEqual(linesA: string[], source: AsyncIterable continue; } + if (aLen !== bLen) { + return false; + } + if (lineA !== lineB) { return false; }