mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-05-31 07:11:00 +02:00
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.
This commit is contained in:
parent
1ebaa03b25
commit
c5296986fa
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user