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:
Jonas Jenwald 2026-07-17 20:55:58 +02:00
parent dd7e3731d1
commit 47f2b22842
3 changed files with 8 additions and 3 deletions

View File

@ -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();
} }
/** /**

View File

@ -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);
} }

View File

@ -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,
})), })),