mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Let getVisibleElements
return a Set containing the visible element id
s
Note how in `PDFPageViewBuffer.resize` we're manually iterating through the visible pages in order to build a Set of the visible page `id`s. By instead moving the building of this Set into the `getVisibleElements` helper function, as part of the existing parsing, this code becomes *ever so slightly* more efficient. Furthermore, more direct access to the visible page `id`s also come in handy in other parts of the viewer as well. In the `BaseViewer.isPageVisible` method we no longer need to loop through the visible pages, but can instead directly check if the pageNumber is visible. In the `PDFRenderingQueue.getHighestPriority` method, when checking for "holes" in the page layout, we can also avoid some unnecessary look-ups this way.
This commit is contained in:
parent
2ac6c939a5
commit
6323f8532a
4 changed files with 30 additions and 26 deletions
|
@ -497,7 +497,8 @@ describe("ui_utils", function () {
|
|||
// This is a reimplementation of getVisibleElements without the
|
||||
// optimizations.
|
||||
function slowGetVisibleElements(scroll, pages) {
|
||||
const views = [];
|
||||
const views = [],
|
||||
ids = new Set();
|
||||
const { scrollLeft, scrollTop } = scroll;
|
||||
const scrollRight = scrollLeft + scroll.clientWidth;
|
||||
const scrollBottom = scrollTop + scroll.clientHeight;
|
||||
|
@ -535,9 +536,10 @@ describe("ui_utils", function () {
|
|||
percent,
|
||||
widthPercent: (fractionWidth * 100) | 0,
|
||||
});
|
||||
ids.add(view.id);
|
||||
}
|
||||
}
|
||||
return { first: views[0], last: views[views.length - 1], views };
|
||||
return { first: views[0], last: views[views.length - 1], views, ids };
|
||||
}
|
||||
|
||||
// This function takes a fixed layout of pages and compares the system under
|
||||
|
@ -699,6 +701,7 @@ describe("ui_utils", function () {
|
|||
first: undefined,
|
||||
last: undefined,
|
||||
views: [],
|
||||
ids: new Set(),
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -715,6 +718,7 @@ describe("ui_utils", function () {
|
|||
first: undefined,
|
||||
last: undefined,
|
||||
views: [],
|
||||
ids: new Set(),
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue