From c5296986fa721ecf8da9bdaf6b7fd6501b2c0b4c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 30 Apr 2026 15:41:29 +0200 Subject: [PATCH] Improve performance of the "caches image resources at the document/page level as expected (issue 11878)" unit-test Compare `Uint32Array`s of the image-data, since that's more efficient than comparing the `Uint8ClampedArray`s directly. --- test/unit/api_spec.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 8415a4b0c..a3393ecf3 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -4844,7 +4844,8 @@ have written that much by now. So, here’s to squashing bugs.`); const pdfDoc = await loadingTask.promise; const { canvasFactory } = pdfDoc; let checkedCopyLocalImage = false, - firstImgData = null; + firstImgData = null, + firstImg32 = null; for (let i = 1; i <= pdfDoc.numPages; i++) { const pdfPage = await pdfDoc.getPage(i); @@ -4895,6 +4896,8 @@ have written that much by now. So, here’s to squashing bugs.`); expect(firstImgData.kind).toEqual(ImageKind.RGB_24BPP); expect(firstImgData.data).toBeInstanceOf(Uint8ClampedArray); expect(firstImgData.data.length).toEqual(25245000); + + firstImg32 = new Uint32Array(firstImgData.data.buffer); } else { const objsPool = i >= NUM_PAGES_THRESHOLD ? commonObjs : objs; const currentImgData = objsPool.get(objId); @@ -4906,10 +4909,10 @@ have written that much by now. So, here’s to squashing bugs.`); expect(currentImgData.kind).toEqual(firstImgData.kind); expect(currentImgData.data).toBeInstanceOf(Uint8ClampedArray); + + const currentImg32 = new Uint32Array(currentImgData.data.buffer); expect( - currentImgData.data.every( - (value, index) => value === firstImgData.data[index] - ) + currentImg32.every((value, index) => value === firstImg32[index]) ).toEqual(true); if (i === NUM_PAGES_THRESHOLD) {