Skip to content
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

Add an abstract base-class, which all the various Stream implementations inherit from #13303

Merged
merged 30 commits into from May 1, 2021

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Apr 27, 2021

By having an abstract base-class, it becomes a lot clearer exactly which methods/getters are expected to exist on all Stream instances.
Furthermore, since a number of the methods are identical for all Stream implementations, this reduces unnecessary code duplication in the Stream, DecodeStream, and ChunkedStream classes.

For e.g. gulp mozcentral, the built pdf.worker.js files decreases from 1 619 329 to 1 616 115 bytes with this patch-series.

The only way to review this is probably one commit at a time, with the ?w=1 flag appended to the URL.

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.

Would it be an idea to maybe split the first five commits off into their own PR since they are only about converting existing files to standard classes, while the other commits are also creating and organizing new files? That would make this PR a bit more manageable.

src/core/base_stream_class.js Outdated Show resolved Hide resolved
@Snuffleupagus Snuffleupagus force-pushed the BaseStream branch 5 times, most recently from 054c0e1 to 8c78857 Compare April 27, 2021 21:39
@Snuffleupagus Snuffleupagus force-pushed the BaseStream branch 2 times, most recently from a258f60 to 56c3774 Compare April 28, 2021 10:07
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/b22e8bc1aff8c08/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://3.101.106.178:8877/43dd513482b187e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/b22e8bc1aff8c08/output.txt

Total script time: 26.91 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/b22e8bc1aff8c08/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/43dd513482b187e/output.txt

Total script time: 29.26 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/43dd513482b187e/reftest-analyzer.html#web=eq.log

@Snuffleupagus Snuffleupagus marked this pull request as ready for review April 28, 2021 11:02
…ons inherit from

By having an abstract base-class, it becomes a lot clearer exactly which methods/getters are expected to exist on all Stream instances.
Furthermore, since a number of the methods are *identical* for all Stream implementations, this reduces unnecessary code duplication in the `Stream`, `DecodeStream`, and `ChunkedStream` classes.

For e.g. `gulp mozcentral`, the *built* `pdf.worker.js` files decreases from `1 619 329` to `1 616 115` bytes with this patch-series.
…tations

The way that `getBaseStreams` is currently handled has bothered me from time to time, especially how we're checking if the method exists before calling it.
By adding a dummy `BaseStream.getBaseStreams` method, and having the call-sites simply check the return value, we can improve some of the relevant code.

Note in particular how the `ObjectLoader._walk` method didn't actually check that the data in question is a Stream instance, and instead only checked the `currentNode` (which could be anything) for the existence of a `getBaseStreams` property.
…ream`/`JpxStream` constructors

For all of the other `DecodeStream`s we're not passing in a `Dict`-instance manually, but instead get it from the `stream`-parameter. Hence there's no particularly good reason, as far as I can tell, to not do the same thing in `Jbig2Stream`/`JpegStream`/`JpxStream` as well.
Looking at the `ChunkedStream` implementation, it's basically a "regular" `Stream` but with added functionality in order to deal with fetching/loading of missing data.
Hence, by letting `ChunkedStream` extend `Stream`, we can remove some duplicate methods from the `ChunkedStream` class.
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/867a598fc00c957/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://3.101.106.178:8877/8b5c7b432c0f809/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/867a598fc00c957/output.txt

Total script time: 25.79 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/867a598fc00c957/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/8b5c7b432c0f809/output.txt

Total script time: 29.69 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/8b5c7b432c0f809/reftest-analyzer.html#web=eq.log

@timvandermeij
Copy link
Contributor

Looks good so far. I'll try to do a full review this weekend since I'll need some time to carefully go over all commits :-)

@timvandermeij timvandermeij merged commit f6f3351 into mozilla:master May 1, 2021
@timvandermeij
Copy link
Contributor

Thank you for all this work; looks much better!

@Snuffleupagus Snuffleupagus deleted the BaseStream branch May 1, 2021 17:21
@Snuffleupagus
Copy link
Collaborator Author

@timvandermeij Thanks a lot for reviewing this patch series; I realize that it cannot have been all that easy, or even fun for that matter!

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.

None yet

3 participants