Let getVisibleElements return a Set containing the visible element ids

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:
Jonas Jenwald 2021-11-01 11:52:45 +01:00
parent 2ac6c939a5
commit 6323f8532a
4 changed files with 30 additions and 26 deletions

View file

@ -473,6 +473,7 @@ function getVisibleElements({
}
const visible = [],
ids = new Set(),
numViews = views.length;
let firstVisibleElementInd = binarySearchFirstItem(
views,
@ -558,6 +559,7 @@ function getVisibleElements({
percent,
widthPercent: (fractionWidth * 100) | 0,
});
ids.add(view.id);
}
const first = visible[0],
@ -572,7 +574,7 @@ function getVisibleElements({
return a.id - b.id; // ensure stability
});
}
return { first, last, views: visible };
return { first, last, views: visible, ids };
}
/**