@@ -42,17 +42,17 @@ pub fn render(
4242 . as_ref ( ) ,
4343 ) ;
4444
45- let mut mod_items = vec ! [ ] ;
46- let mut r_impl_items = vec ! [ ] ;
47- let mut w_impl_items = vec ! [ ] ;
45+ let mut mod_items = TokenStream :: new ( ) ;
46+ let mut r_impl_items = TokenStream :: new ( ) ;
47+ let mut w_impl_items = TokenStream :: new ( ) ;
4848 let mut methods = vec ! [ ] ;
4949
5050 let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ] . contains ( & access) ;
5151 let can_write = access != Access :: ReadOnly ;
5252
5353 if can_read {
5454 let desc = format ! ( "Reader of register {}" , register. name) ;
55- mod_items. push ( quote ! {
55+ mod_items. extend ( quote ! {
5656 #[ doc = #desc]
5757 pub type R = crate :: R <#rty, super :: #name_pc>;
5858 } ) ;
@@ -62,13 +62,13 @@ pub fn render(
6262 let res_val = register. reset_value . or ( defs. reset_value ) . map ( |v| v as u64 ) ;
6363 if can_write {
6464 let desc = format ! ( "Writer for register {}" , register. name) ;
65- mod_items. push ( quote ! {
65+ mod_items. extend ( quote ! {
6666 #[ doc = #desc]
6767 pub type W = crate :: W <#rty, super :: #name_pc>;
6868 } ) ;
6969 if let Some ( rv) = res_val. map ( util:: hex) {
7070 let doc = format ! ( "Register {} `reset()`'s with value {}" , register. name, & rv) ;
71- mod_items. push ( quote ! {
71+ mod_items. extend ( quote ! {
7272 #[ doc = #doc]
7373 impl crate :: ResetValue for super :: #name_pc {
7474 type Type = #rty;
@@ -116,33 +116,25 @@ pub fn render(
116116 let close = Punct :: new ( '}' , Spacing :: Alone ) ;
117117
118118 if can_read {
119- mod_items. push ( quote ! {
119+ mod_items. extend ( quote ! {
120120 impl R #open
121121 } ) ;
122122
123- for item in r_impl_items {
124- mod_items. push ( quote ! {
125- #item
126- } ) ;
127- }
123+ mod_items. extend ( r_impl_items) ;
128124
129- mod_items. push ( quote ! {
125+ mod_items. extend ( quote ! {
130126 #close
131127 } ) ;
132128 }
133129
134130 if can_write {
135- mod_items. push ( quote ! {
131+ mod_items. extend ( quote ! {
136132 impl W #open
137133 } ) ;
138134
139- for item in w_impl_items {
140- mod_items. push ( quote ! {
141- #item
142- } ) ;
143- }
135+ mod_items. extend ( w_impl_items) ;
144136
145- mod_items. push ( quote ! {
137+ mod_items. extend ( quote ! {
146138 #close
147139 } ) ;
148140 }
@@ -197,11 +189,7 @@ pub fn render(
197189 pub mod #name_sc #open
198190 } ) ;
199191
200- for item in mod_items {
201- out. extend ( quote ! {
202- #item
203- } ) ;
204- }
192+ out. extend ( mod_items) ;
205193
206194 out. extend ( quote ! {
207195 #close
@@ -219,9 +207,9 @@ pub fn fields(
219207 rty : & Ident ,
220208 reset_value : Option < u64 > ,
221209 access : Access ,
222- mod_items : & mut Vec < TokenStream > ,
223- r_impl_items : & mut Vec < TokenStream > ,
224- w_impl_items : & mut Vec < TokenStream > ,
210+ mod_items : & mut TokenStream ,
211+ r_impl_items : & mut TokenStream ,
212+ w_impl_items : & mut TokenStream ,
225213) -> Result < ( ) > {
226214 // TODO enumeratedValues
227215 for f in fields. into_iter ( ) {
@@ -297,7 +285,7 @@ pub fn fields(
297285 if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Read ) {
298286 evs_r = Some ( evs. clone ( ) ) ;
299287
300- r_impl_items. push ( quote ! {
288+ r_impl_items. extend ( quote ! {
301289 #[ doc = #description_with_bits]
302290 #[ inline( always) ]
303291 pub fn #sc( & self ) -> #_pc_r {
@@ -311,7 +299,7 @@ pub fn fields(
311299 derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, & description) ;
312300
313301 let doc = format ! ( "Reader of field `{}`" , f. name) ;
314- mod_items. push ( quote ! {
302+ mod_items. extend ( quote ! {
315303 #[ doc = #doc]
316304 pub type #_pc_r = crate :: R <#fty, #pc_r>;
317305 } ) ;
@@ -394,7 +382,7 @@ pub fn fields(
394382 }
395383
396384 let doc = format ! ( "Reader of field `{}`" , f. name) ;
397- mod_items. push ( quote ! {
385+ mod_items. extend ( quote ! {
398386 #[ doc = #doc]
399387 pub type #_pc_r = crate :: R <#fty, #pc_r>;
400388 impl #_pc_r {
@@ -403,7 +391,7 @@ pub fn fields(
403391 } ) ;
404392 }
405393 } else {
406- r_impl_items. push ( quote ! {
394+ r_impl_items. extend ( quote ! {
407395 #[ doc = #description_with_bits]
408396 #[ inline( always) ]
409397 pub fn #sc( & self ) -> #_pc_r {
@@ -412,7 +400,7 @@ pub fn fields(
412400 } ) ;
413401
414402 let doc = format ! ( "Reader of field `{}`" , f. name) ;
415- mod_items. push ( quote ! {
403+ mod_items. extend ( quote ! {
416404 #[ doc = #doc]
417405 pub type #_pc_r = crate :: R <#fty, #fty>;
418406 } )
@@ -507,7 +495,7 @@ pub fn fields(
507495 } ) ;
508496
509497 let doc = format ! ( "Write proxy for field `{}`" , f. name) ;
510- mod_items. push ( quote ! {
498+ mod_items. extend ( quote ! {
511499 #[ doc = #doc]
512500 pub struct #_pc_w<' a> {
513501 w: & ' a mut W ,
@@ -518,7 +506,7 @@ pub fn fields(
518506 }
519507 } ) ;
520508
521- w_impl_items. push ( quote ! {
509+ w_impl_items. extend ( quote ! {
522510 #[ doc = #description_with_bits]
523511 #[ inline( always) ]
524512 pub fn #sc( & mut self ) -> #_pc_w {
@@ -586,7 +574,7 @@ impl Variant {
586574}
587575
588576fn add_from_variants (
589- mod_items : & mut Vec < TokenStream > ,
577+ mod_items : & mut TokenStream ,
590578 variants : & [ Variant ] ,
591579 pc : & Ident ,
592580 fty : & Ident ,
@@ -618,7 +606,7 @@ fn add_from_variants(
618606 desc. to_owned ( )
619607 } ;
620608
621- mod_items. push ( quote ! {
609+ mod_items. extend ( quote ! {
622610 #[ doc = #desc]
623611 #[ derive( Clone , Copy , Debug , PartialEq ) ]
624612 #repr
@@ -635,7 +623,7 @@ fn add_from_variants(
635623}
636624
637625fn derive_from_base (
638- mod_items : & mut Vec < TokenStream > ,
626+ mod_items : & mut TokenStream ,
639627 base : & Base ,
640628 pc : & Ident ,
641629 base_pc : & Ident ,
@@ -648,7 +636,7 @@ fn derive_from_base(
648636 let pmod_ = Ident :: new ( & pmod_, span) ;
649637 let rmod_ = Ident :: new ( & rmod_, span) ;
650638
651- mod_items. push ( quote ! {
639+ mod_items. extend ( quote ! {
652640 #[ doc = #desc]
653641 pub type #pc =
654642 crate :: #pmod_:: #rmod_:: #base_pc;
@@ -657,13 +645,13 @@ fn derive_from_base(
657645 let mod_ = register. to_sanitized_snake_case ( ) ;
658646 let mod_ = Ident :: new ( & mod_, span) ;
659647
660- mod_items. push ( quote ! {
648+ mod_items. extend ( quote ! {
661649 #[ doc = #desc]
662650 pub type #pc =
663651 super :: #mod_:: #base_pc;
664652 } ) ;
665653 } else {
666- mod_items. push ( quote ! {
654+ mod_items. extend ( quote ! {
667655 #[ doc = #desc]
668656 pub type #pc = #base_pc;
669657 } ) ;
0 commit comments