mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 08:27:19 +02:00
Use Iterator methods to avoid some unnecessary Array creation
Currently there are some spots in the code-base where intermediate Arrays are unnecessarily created from Iterators, before `filter` and `map` is used to create a final Array. Thanks to newer Iterators methods, see e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/filter, that can be now be avoided.
This commit is contained in:
parent
dd7e3731d1
commit
47f2b22842
@ -447,7 +447,10 @@ class XFAObject {
|
|||||||
[_getUnsetAttributes](protoAttributes) {
|
[_getUnsetAttributes](protoAttributes) {
|
||||||
const allAttr = this[_attributeNames];
|
const allAttr = this[_attributeNames];
|
||||||
const setAttr = this[_setAttributes];
|
const setAttr = this[_setAttributes];
|
||||||
return [...protoAttributes].filter(x => allAttr.has(x) && !setAttr.has(x));
|
return protoAttributes
|
||||||
|
.keys()
|
||||||
|
.filter(x => allAttr.has(x) && !setAttr.has(x))
|
||||||
|
.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -366,8 +366,10 @@ class DrawLayer {
|
|||||||
* Connected text layers sorted in document order.
|
* Connected text layers sorted in document order.
|
||||||
*/
|
*/
|
||||||
static #getOrderedTextLayers() {
|
static #getOrderedTextLayers() {
|
||||||
return [...this.#textLayerSet]
|
return this.#textLayerSet
|
||||||
|
.keys()
|
||||||
.filter(textLayer => textLayer.isConnected)
|
.filter(textLayer => textLayer.isConnected)
|
||||||
|
.toArray()
|
||||||
.sort(compareTextLayers);
|
.sort(compareTextLayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,7 @@ class MathMLSanitizer {
|
|||||||
"sanitizer",
|
"sanitizer",
|
||||||
FeatureTest.isSanitizerSupported
|
FeatureTest.isSanitizerSupported
|
||||||
? new Sanitizer({
|
? new Sanitizer({
|
||||||
elements: [...MathMLElements].map(name => ({
|
elements: Array.from(MathMLElements.keys(), name => ({
|
||||||
name,
|
name,
|
||||||
namespace: MathMLNamespace,
|
namespace: MathMLNamespace,
|
||||||
})),
|
})),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user