Skip to content

Let getVisibleElements return a Set containing the visible element ids #14219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2021

Conversation

Snuffleupagus
Copy link
Collaborator

Note how in PDFPageViewBuffer.resize we're manually iterating through the visible pages in order to build a Set of the visible page ids. 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 ids 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.

}

/**
* @param {number} pageNumber
*/
isPageCached(pageNumber) {
if (!this.pdfDocument || !this._buffer) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly unrelated to the rest of the patch, but: Note that this._buffer will always be defined whenever this.pdfDocument is set.

Comment on lines -1299 to -1301
if (!pageView) {
return false;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly unrelated to the rest of the patch, but: Given the existing validation just above it shouldn't be possible for pageView to be undefined here, and in any case passing undefined to the PDFPageViewBuffer.has-method won't break anything.

@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Nov 2, 2021

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/76a28cbc05ce67c/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 2, 2021

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/76a28cbc05ce67c/output.txt

Total script time: 4.23 mins

Published

Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good improvement. r=me once rebased; thanks!

…`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.
The way that we're currently handling the last-`id` is very old, and there's no longer any good reason to special-case things when only one thumbnail is visible.
Furthermore, we can also modernize the loop slightly by using `for...of` instead of `Array.prototype.some()` when checking for fully visible thumbnails.
@Snuffleupagus Snuffleupagus force-pushed the getVisibleElements-ids branch from ece6728 to e78e4e7 Compare November 3, 2021 20:15
@Snuffleupagus
Copy link
Collaborator Author

/botio integrationtest

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/97ad3126ba9d731/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.193.163.58:8877/09eea1a0136b257/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/97ad3126ba9d731/output.txt

Total script time: 3.92 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/09eea1a0136b257/output.txt

Total script time: 6.35 mins

  • Integration Tests: FAILED

@Snuffleupagus Snuffleupagus merged commit 611627f into mozilla:master Nov 3, 2021
@Snuffleupagus Snuffleupagus deleted the getVisibleElements-ids branch November 3, 2021 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants