Use more for...of loops in the viewer

Note that the arrays that we're looping over here are by definition *dense*, hence there's no point in checking if each element actually exists first.
This commit is contained in:
Jonas Jenwald 2022-04-23 12:46:38 +02:00
parent f39219cd45
commit 7e57469683
2 changed files with 12 additions and 22 deletions

View File

@ -1467,12 +1467,9 @@ class BaseViewer {
}
cleanup() {
for (let i = 0, ii = this._pages.length; i < ii; i++) {
if (
this._pages[i] &&
this._pages[i].renderingState !== RenderingStates.FINISHED
) {
this._pages[i].reset();
for (const pageView of this._pages) {
if (pageView.renderingState !== RenderingStates.FINISHED) {
pageView.reset();
}
}
}
@ -1481,10 +1478,8 @@ class BaseViewer {
* @private
*/
_cancelRendering() {
for (let i = 0, ii = this._pages.length; i < ii; i++) {
if (this._pages[i]) {
this._pages[i].cancelRendering();
}
for (const pageView of this._pages) {
pageView.cancelRendering();
}
}
@ -1873,8 +1868,8 @@ class BaseViewer {
viewer.textContent = "";
if (this._spreadMode === SpreadMode.NONE) {
for (let i = 0, ii = pages.length; i < ii; ++i) {
viewer.appendChild(pages[i].div);
for (const pageView of this._pages) {
viewer.appendChild(pageView.div);
}
} else {
const parity = this._spreadMode - 1;

View File

@ -151,12 +151,9 @@ class PDFThumbnailViewer {
}
cleanup() {
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
if (
this._thumbnails[i] &&
this._thumbnails[i].renderingState !== RenderingStates.FINISHED
) {
this._thumbnails[i].reset();
for (const thumbnail of this._thumbnails) {
if (thumbnail.renderingState !== RenderingStates.FINISHED) {
thumbnail.reset();
}
}
TempImageFactory.destroyCanvas();
@ -237,10 +234,8 @@ class PDFThumbnailViewer {
* @private
*/
_cancelRendering() {
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
if (this._thumbnails[i]) {
this._thumbnails[i].cancelRendering();
}
for (const thumbnail of this._thumbnails) {
thumbnail.cancelRendering();
}
}