mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Add an abstract base-class, which all the various Stream implementations 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.
This commit is contained in:
parent
6151b4ecac
commit
67415bfabe
6 changed files with 138 additions and 158 deletions
|
@ -61,12 +61,8 @@ class ObjectLoader {
|
|||
}
|
||||
|
||||
async load() {
|
||||
// Don't walk the graph if all the data is already loaded; note that only
|
||||
// `ChunkedStream` instances have a `allChunksLoaded` method.
|
||||
if (
|
||||
!this.xref.stream.allChunksLoaded ||
|
||||
this.xref.stream.allChunksLoaded()
|
||||
) {
|
||||
// Don't walk the graph if all the data is already loaded.
|
||||
if (this.xref.stream.isDataLoaded) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -115,12 +111,12 @@ class ObjectLoader {
|
|||
if (currentNode && currentNode.getBaseStreams) {
|
||||
const baseStreams = currentNode.getBaseStreams();
|
||||
let foundMissingData = false;
|
||||
for (let i = 0, ii = baseStreams.length; i < ii; i++) {
|
||||
const stream = baseStreams[i];
|
||||
if (stream.allChunksLoaded && !stream.allChunksLoaded()) {
|
||||
foundMissingData = true;
|
||||
pendingRequests.push({ begin: stream.start, end: stream.end });
|
||||
for (const stream of baseStreams) {
|
||||
if (stream.isDataLoaded) {
|
||||
continue;
|
||||
}
|
||||
foundMissingData = true;
|
||||
pendingRequests.push({ begin: stream.start, end: stream.end });
|
||||
}
|
||||
if (foundMissingData) {
|
||||
nodesToRevisit.push(currentNode);
|
||||
|
@ -133,8 +129,7 @@ class ObjectLoader {
|
|||
if (pendingRequests.length) {
|
||||
await this.xref.stream.manager.requestRanges(pendingRequests);
|
||||
|
||||
for (let i = 0, ii = nodesToRevisit.length; i < ii; i++) {
|
||||
const node = nodesToRevisit[i];
|
||||
for (const node of nodesToRevisit) {
|
||||
// Remove any reference nodes from the current `RefSet` so they
|
||||
// aren't skipped when we revist them.
|
||||
if (node instanceof Ref) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue