@@ -29,25 +29,28 @@ const MALFORMED_ATTRIBUTES_ERROR: &str = "Malformed XML attributes";
2929/// Note: Keys are cloned to `Vec<u8>` because `quick_xml::Attribute` owns the key
3030/// data only for the lifetime of the event, but we need to store attributes across
3131/// multiple parsing calls in `parse_enclosure` and other functions.
32+ ///
33+ /// Pre-allocates space for 4 attributes (typical for enclosures: url, type, length, maybe one more)
3234#[ inline]
3335fn collect_attributes ( e : & quick_xml:: events:: BytesStart ) -> ( Vec < ( Vec < u8 > , String ) > , bool ) {
3436 let mut has_errors = false ;
35- let attrs = e
36- . attributes ( )
37- . filter_map ( |result| {
38- if let Ok ( attr) = result {
37+ let mut attrs = Vec :: with_capacity ( 4 ) ;
38+
39+ for result in e. attributes ( ) {
40+ match result {
41+ Ok ( attr) => {
3942 if let Ok ( v) = attr. unescape_value ( ) {
40- Some ( ( attr. key . as_ref ( ) . to_vec ( ) , v. to_string ( ) ) )
43+ attrs . push ( ( attr. key . as_ref ( ) . to_vec ( ) , v. to_string ( ) ) ) ;
4144 } else {
4245 has_errors = true ;
43- None
4446 }
45- } else {
47+ }
48+ Err ( _) => {
4649 has_errors = true ;
47- None
4850 }
49- } )
50- . collect ( ) ;
51+ }
52+ }
53+
5154 ( attrs, has_errors)
5255}
5356
@@ -330,7 +333,7 @@ fn parse_channel_standard(
330333 feed. feed . set_title ( TextConstruct {
331334 value : text,
332335 content_type : TextType :: Text ,
333- language : channel_lang. map ( String :: from ) ,
336+ language : channel_lang. map ( std :: convert :: Into :: into ) ,
334337 base : base_ctx. base ( ) . map ( String :: from) ,
335338 } ) ;
336339 }
@@ -348,12 +351,12 @@ fn parse_channel_standard(
348351 feed. feed . set_subtitle ( TextConstruct {
349352 value : text,
350353 content_type : TextType :: Html ,
351- language : channel_lang. map ( String :: from ) ,
354+ language : channel_lang. map ( std :: convert :: Into :: into ) ,
352355 base : base_ctx. base ( ) . map ( String :: from) ,
353356 } ) ;
354357 }
355358 b"language" => {
356- feed. feed . language = Some ( read_text ( reader, buf, limits) ?) ;
359+ feed. feed . language = Some ( read_text ( reader, buf, limits) ?. into ( ) ) ;
357360 }
358361 b"pubDate" => {
359362 let text = read_text ( reader, buf, limits) ?;
@@ -367,10 +370,10 @@ fn parse_channel_standard(
367370 }
368371 }
369372 b"managingEditor" => {
370- feed. feed . author = Some ( read_text ( reader, buf, limits) ?) ;
373+ feed. feed . author = Some ( read_text ( reader, buf, limits) ?. into ( ) ) ;
371374 }
372375 b"webMaster" => {
373- feed. feed . publisher = Some ( read_text ( reader, buf, limits) ?) ;
376+ feed. feed . publisher = Some ( read_text ( reader, buf, limits) ?. into ( ) ) ;
374377 }
375378 b"generator" => {
376379 feed. feed . generator = Some ( read_text ( reader, buf, limits) ?) ;
@@ -383,7 +386,7 @@ fn parse_channel_standard(
383386 let term = read_text ( reader, buf, limits) ?;
384387 feed. feed . tags . try_push_limited (
385388 Tag {
386- term,
389+ term : term . into ( ) ,
387390 scheme : None ,
388391 label : None ,
389392 } ,
@@ -750,7 +753,7 @@ fn parse_item_standard(
750753 entry. set_title ( TextConstruct {
751754 value : text,
752755 content_type : TextType :: Text ,
753- language : item_lang. map ( String :: from ) ,
756+ language : item_lang. map ( std :: convert :: Into :: into ) ,
754757 base : base_ctx. base ( ) . map ( String :: from) ,
755758 } ) ;
756759 }
@@ -761,7 +764,7 @@ fn parse_item_standard(
761764 entry. links . try_push_limited (
762765 Link {
763766 href : resolved_link. into ( ) ,
764- rel : Some ( "alternate" . to_string ( ) ) ,
767+ rel : Some ( "alternate" . into ( ) ) ,
765768 ..Default :: default ( )
766769 } ,
767770 limits. max_links_per_entry ,
@@ -772,25 +775,25 @@ fn parse_item_standard(
772775 entry. set_summary ( TextConstruct {
773776 value : text,
774777 content_type : TextType :: Html ,
775- language : item_lang. map ( String :: from ) ,
778+ language : item_lang. map ( std :: convert :: Into :: into ) ,
776779 base : base_ctx. base ( ) . map ( String :: from) ,
777780 } ) ;
778781 }
779782 b"guid" => {
780- entry. id = Some ( read_text ( reader, buf, limits) ?) ;
783+ entry. id = Some ( read_text ( reader, buf, limits) ?. into ( ) ) ;
781784 }
782785 b"pubDate" => {
783786 let text = read_text ( reader, buf, limits) ?;
784787 entry. published = parse_date ( & text) ;
785788 }
786789 b"author" => {
787- entry. author = Some ( read_text ( reader, buf, limits) ?) ;
790+ entry. author = Some ( read_text ( reader, buf, limits) ?. into ( ) ) ;
788791 }
789792 b"category" => {
790793 let term = read_text ( reader, buf, limits) ?;
791794 entry. tags . try_push_limited (
792795 Tag {
793- term,
796+ term : term . into ( ) ,
794797 scheme : None ,
795798 label : None ,
796799 } ,
@@ -1348,7 +1351,7 @@ fn parse_podcast_value(
13481351 let suggested = find_attribute ( attrs, b"suggested" )
13491352 . map ( |v| truncate_to_length ( v, limits. max_attribute_length ) ) ;
13501353
1351- let mut recipients = Vec :: new ( ) ;
1354+ let mut recipients = Vec :: with_capacity ( 2 ) ;
13521355
13531356 loop {
13541357 match reader. read_event_into ( buf) {
0 commit comments