Skip to content

Commit b7cc272

Browse files
committed
Optimize the removal of unused namespaces
1 parent 0078598 commit b7cc272

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/src/xml/builder.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,13 @@ class XmlBuilder {
201201
if (optimizeNamespaces) {
202202
// Remove unused namespaces: The reason we first add them and then remove
203203
// them again is to keep the order in which they have been added.
204-
element.namespaces.forEach((uri, meta) {
205-
if (!meta.used) {
206-
final qualified = meta.name.qualified;
207-
final attribute = element.attributes.firstWhere(
208-
(attribute) => attribute.name.qualified == qualified,
209-
);
210-
element.attributes.remove(attribute);
211-
}
212-
});
204+
final toRemove = element.namespaces.values
205+
.where((meta) => !meta.used)
206+
.map((meta) => meta.name.qualified)
207+
.toSet();
208+
element.attributes.removeWhere(
209+
(attribute) => toRemove.contains(attribute.name.qualified),
210+
);
213211
}
214212
} finally {
215213
_stack.removeLast();

0 commit comments

Comments
 (0)