Skip to content

Commit

Permalink
Simplify the newRefs computation in the "SaveDocument"-handler in t…
Browse files Browse the repository at this point in the history
…he worker-thread

 - Let the `Page.save`-method filter out "empty" entries, similar to the `Page._parsedAnnotations`-getter, since that on its own already simplifies the "SaveDocument"-handler a tiny bit.

 - The existing `reduce` and `concat` construction isn't exactly a wonder of readability :-)
   Thanks to modern JavaScript features it should be possible to replace all of this with `Array.prototype.flat()` instead, which at least to me feels a lot easier to understand.
  • Loading branch information
Snuffleupagus committed Jun 19, 2022
1 parent 45de73b commit 57c10ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ class Page {
);
}

return Promise.all(newRefsPromises);
return Promise.all(newRefsPromises).then(function (newRefs) {
return newRefs.filter(newRef => !!newRef);
});
});
}

Expand Down
6 changes: 1 addition & 5 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,7 @@ class WorkerMessageHandler {
return stream.bytes;
}
} else {
for (const ref of refs) {
newRefs = ref
.filter(x => x !== null)
.reduce((a, b) => a.concat(b), newRefs);
}
newRefs = refs.flat(2);

if (newRefs.length === 0) {
// No new refs so just return the initial bytes
Expand Down

0 comments on commit 57c10ac

Please sign in to comment.