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

View File

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