Skip to content

Commit 3940855

Browse files
committed
Use Map.prototype.getOrInsert() in the _getPageAdvance method
Also, change the method to an actually private one.
1 parent f548a15 commit 3940855

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

web/pdf_viewer.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,10 +2270,7 @@ class PDFViewer {
22702270
this.update();
22712271
}
22722272

2273-
/**
2274-
* @private
2275-
*/
2276-
_getPageAdvance(currentPageNumber, previous = false) {
2273+
#getPageAdvance(currentPageNumber, previous = false) {
22772274
switch (this._scrollMode) {
22782275
case ScrollMode.WRAPPED: {
22792276
const { views } = this._getVisiblePages(),
@@ -2284,11 +2281,7 @@ class PDFViewer {
22842281
if (percent === 0 || widthPercent < 100) {
22852282
continue;
22862283
}
2287-
let yArray = pageLayout.get(y);
2288-
if (!yArray) {
2289-
pageLayout.set(y, (yArray ||= []));
2290-
}
2291-
yArray.push(id);
2284+
pageLayout.getOrInsert(y, []).push(id);
22922285
}
22932286
// Find the row of the current page.
22942287
for (const yArray of pageLayout.values()) {
@@ -2379,7 +2372,7 @@ class PDFViewer {
23792372
return false;
23802373
}
23812374
const advance =
2382-
this._getPageAdvance(currentPageNumber, /* previous = */ false) || 1;
2375+
this.#getPageAdvance(currentPageNumber, /* previous = */ false) || 1;
23832376

23842377
this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
23852378
return true;
@@ -2396,7 +2389,7 @@ class PDFViewer {
23962389
return false;
23972390
}
23982391
const advance =
2399-
this._getPageAdvance(currentPageNumber, /* previous = */ true) || 1;
2392+
this.#getPageAdvance(currentPageNumber, /* previous = */ true) || 1;
24002393

24012394
this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
24022395
return true;

0 commit comments

Comments
 (0)