Browse Source

Perf: improve file comparision

SukkaW 1 year ago
parent
commit
3952e27d64
1 changed files with 13 additions and 3 deletions
  1. 13 3
      Build/lib/create-file.ts

+ 13 - 3
Build/lib/create-file.ts

@@ -14,6 +14,10 @@ export async function fileEqual(linesA: string[], source: AsyncIterable<string>
   const linesABound = linesA.length - 1;
   const linesABound = linesA.length - 1;
 
 
   let index = -1;
   let index = -1;
+
+  let aLen = 0;
+  let bLen = 0;
+
   for await (const lineB of source) {
   for await (const lineB of source) {
     index++;
     index++;
 
 
@@ -22,9 +26,11 @@ export async function fileEqual(linesA: string[], source: AsyncIterable<string>
     }
     }
 
 
     const lineA = linesA[index];
     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
         // both lines are empty, check next line
         continue;
         continue;
       }
       }
@@ -32,7 +38,7 @@ export async function fileEqual(linesA: string[], source: AsyncIterable<string>
       return false;
       return false;
     }
     }
     // now lineA can not be empty
     // now lineA can not be empty
-    if (lineB.length === 0) {
+    if (bLen === 0) {
       // lineB is empty but lineA is not
       // lineB is empty but lineA is not
       return false;
       return false;
     }
     }
@@ -63,6 +69,10 @@ export async function fileEqual(linesA: string[], source: AsyncIterable<string>
       continue;
       continue;
     }
     }
 
 
+    if (aLen !== bLen) {
+      return false;
+    }
+
     if (lineA !== lineB) {
     if (lineA !== lineB) {
       return false;
       return false;
     }
     }