@@ -196,9 +196,6 @@ pub struct XmlTreeBuilder<Handle, Sink> {
196
196
/// Current namespace identifier
197
197
current_namespace : NamespaceMap ,
198
198
199
- /// List of already present namespace local name attribute pairs.
200
- present_attrs : HashSet < ( Namespace , LocalName ) > ,
201
-
202
199
/// Current tree builder phase.
203
200
phase : XmlPhase ,
204
201
}
@@ -221,7 +218,6 @@ where
221
218
curr_elem : None ,
222
219
namespace_stack : NamespaceMapStack :: new ( ) ,
223
220
current_namespace : NamespaceMap :: empty ( ) ,
224
- present_attrs : HashSet :: new ( ) ,
225
221
phase : Start ,
226
222
}
227
223
}
@@ -307,28 +303,38 @@ where
307
303
// existing namespace context.
308
304
//
309
305
// Returns false if the attribute is a duplicate, returns true otherwise.
310
- fn bind_attr_qname ( & mut self , name : & mut QualName ) -> bool {
306
+ fn bind_attr_qname (
307
+ & mut self ,
308
+ present_attrs : & mut HashSet < ( Namespace , LocalName ) > ,
309
+ name : & mut QualName ,
310
+ ) -> bool {
311
311
// Attributes don't have default namespace
312
312
let mut not_duplicate = true ;
313
313
314
314
if name. prefix . is_some ( ) {
315
315
self . bind_qname ( name) ;
316
- not_duplicate = self . check_duplicate_attr ( name) ;
316
+ not_duplicate = Self :: check_duplicate_attr ( present_attrs , name) ;
317
317
}
318
318
not_duplicate
319
319
}
320
320
321
- fn check_duplicate_attr ( & mut self , name : & QualName ) -> bool {
321
+ fn check_duplicate_attr (
322
+ present_attrs : & mut HashSet < ( Namespace , LocalName ) > ,
323
+ name : & QualName ,
324
+ ) -> bool {
322
325
let pair = ( name. ns . clone ( ) , name. local . clone ( ) ) ;
323
326
324
- if self . present_attrs . contains ( & pair) {
327
+ if present_attrs. contains ( & pair) {
325
328
return false ;
326
329
}
327
- self . present_attrs . insert ( pair) ;
330
+ present_attrs. insert ( pair) ;
328
331
true
329
332
}
330
333
331
334
fn process_namespaces ( & mut self , tag : & mut Tag ) {
335
+ // List of already present namespace local name attribute pairs.
336
+ let mut present_attrs: HashSet < ( Namespace , LocalName ) > = Default :: default ( ) ;
337
+
332
338
let mut new_attr = vec ! [ ] ;
333
339
// First we extract all namespace declarations
334
340
for attr in tag. attrs . iter_mut ( ) . filter ( |attr| {
@@ -343,7 +349,7 @@ where
343
349
attr. name . prefix != Some ( namespace_prefix ! ( "xmlns" ) )
344
350
&& attr. name . local != local_name ! ( "xmlns" )
345
351
} ) {
346
- if self . bind_attr_qname ( & mut attr. name ) {
352
+ if self . bind_attr_qname ( & mut present_attrs , & mut attr. name ) {
347
353
new_attr. push ( attr. clone ( ) ) ;
348
354
}
349
355
}
0 commit comments