@@ -42,17 +42,17 @@ pub fn render(
42
42
. as_ref ( ) ,
43
43
) ;
44
44
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 ( ) ;
48
48
let mut methods = vec ! [ ] ;
49
49
50
50
let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ] . contains ( & access) ;
51
51
let can_write = access != Access :: ReadOnly ;
52
52
53
53
if can_read {
54
54
let desc = format ! ( "Reader of register {}" , register. name) ;
55
- mod_items. push ( quote ! {
55
+ mod_items. extend ( quote ! {
56
56
#[ doc = #desc]
57
57
pub type R = crate :: R <#rty, super :: #name_pc>;
58
58
} ) ;
@@ -62,13 +62,13 @@ pub fn render(
62
62
let res_val = register. reset_value . or ( defs. reset_value ) . map ( |v| v as u64 ) ;
63
63
if can_write {
64
64
let desc = format ! ( "Writer for register {}" , register. name) ;
65
- mod_items. push ( quote ! {
65
+ mod_items. extend ( quote ! {
66
66
#[ doc = #desc]
67
67
pub type W = crate :: W <#rty, super :: #name_pc>;
68
68
} ) ;
69
69
if let Some ( rv) = res_val. map ( util:: hex) {
70
70
let doc = format ! ( "Register {} `reset()`'s with value {}" , register. name, & rv) ;
71
- mod_items. push ( quote ! {
71
+ mod_items. extend ( quote ! {
72
72
#[ doc = #doc]
73
73
impl crate :: ResetValue for super :: #name_pc {
74
74
type Type = #rty;
@@ -116,33 +116,25 @@ pub fn render(
116
116
let close = Punct :: new ( '}' , Spacing :: Alone ) ;
117
117
118
118
if can_read {
119
- mod_items. push ( quote ! {
119
+ mod_items. extend ( quote ! {
120
120
impl R #open
121
121
} ) ;
122
122
123
- for item in r_impl_items {
124
- mod_items. push ( quote ! {
125
- #item
126
- } ) ;
127
- }
123
+ mod_items. extend ( r_impl_items) ;
128
124
129
- mod_items. push ( quote ! {
125
+ mod_items. extend ( quote ! {
130
126
#close
131
127
} ) ;
132
128
}
133
129
134
130
if can_write {
135
- mod_items. push ( quote ! {
131
+ mod_items. extend ( quote ! {
136
132
impl W #open
137
133
} ) ;
138
134
139
- for item in w_impl_items {
140
- mod_items. push ( quote ! {
141
- #item
142
- } ) ;
143
- }
135
+ mod_items. extend ( w_impl_items) ;
144
136
145
- mod_items. push ( quote ! {
137
+ mod_items. extend ( quote ! {
146
138
#close
147
139
} ) ;
148
140
}
@@ -197,11 +189,7 @@ pub fn render(
197
189
pub mod #name_sc #open
198
190
} ) ;
199
191
200
- for item in mod_items {
201
- out. extend ( quote ! {
202
- #item
203
- } ) ;
204
- }
192
+ out. extend ( mod_items) ;
205
193
206
194
out. extend ( quote ! {
207
195
#close
@@ -219,9 +207,9 @@ pub fn fields(
219
207
rty : & Ident ,
220
208
reset_value : Option < u64 > ,
221
209
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 ,
225
213
) -> Result < ( ) > {
226
214
// TODO enumeratedValues
227
215
for f in fields. into_iter ( ) {
@@ -297,7 +285,7 @@ pub fn fields(
297
285
if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Read ) {
298
286
evs_r = Some ( evs. clone ( ) ) ;
299
287
300
- r_impl_items. push ( quote ! {
288
+ r_impl_items. extend ( quote ! {
301
289
#[ doc = #description_with_bits]
302
290
#[ inline( always) ]
303
291
pub fn #sc( & self ) -> #_pc_r {
@@ -311,7 +299,7 @@ pub fn fields(
311
299
derive_from_base ( mod_items, & base, & pc_r, & base_pc_r, & description) ;
312
300
313
301
let doc = format ! ( "Reader of field `{}`" , f. name) ;
314
- mod_items. push ( quote ! {
302
+ mod_items. extend ( quote ! {
315
303
#[ doc = #doc]
316
304
pub type #_pc_r = crate :: R <#fty, #pc_r>;
317
305
} ) ;
@@ -394,7 +382,7 @@ pub fn fields(
394
382
}
395
383
396
384
let doc = format ! ( "Reader of field `{}`" , f. name) ;
397
- mod_items. push ( quote ! {
385
+ mod_items. extend ( quote ! {
398
386
#[ doc = #doc]
399
387
pub type #_pc_r = crate :: R <#fty, #pc_r>;
400
388
impl #_pc_r {
@@ -403,7 +391,7 @@ pub fn fields(
403
391
} ) ;
404
392
}
405
393
} else {
406
- r_impl_items. push ( quote ! {
394
+ r_impl_items. extend ( quote ! {
407
395
#[ doc = #description_with_bits]
408
396
#[ inline( always) ]
409
397
pub fn #sc( & self ) -> #_pc_r {
@@ -412,7 +400,7 @@ pub fn fields(
412
400
} ) ;
413
401
414
402
let doc = format ! ( "Reader of field `{}`" , f. name) ;
415
- mod_items. push ( quote ! {
403
+ mod_items. extend ( quote ! {
416
404
#[ doc = #doc]
417
405
pub type #_pc_r = crate :: R <#fty, #fty>;
418
406
} )
@@ -507,7 +495,7 @@ pub fn fields(
507
495
} ) ;
508
496
509
497
let doc = format ! ( "Write proxy for field `{}`" , f. name) ;
510
- mod_items. push ( quote ! {
498
+ mod_items. extend ( quote ! {
511
499
#[ doc = #doc]
512
500
pub struct #_pc_w<' a> {
513
501
w: & ' a mut W ,
@@ -518,7 +506,7 @@ pub fn fields(
518
506
}
519
507
} ) ;
520
508
521
- w_impl_items. push ( quote ! {
509
+ w_impl_items. extend ( quote ! {
522
510
#[ doc = #description_with_bits]
523
511
#[ inline( always) ]
524
512
pub fn #sc( & mut self ) -> #_pc_w {
@@ -586,7 +574,7 @@ impl Variant {
586
574
}
587
575
588
576
fn add_from_variants (
589
- mod_items : & mut Vec < TokenStream > ,
577
+ mod_items : & mut TokenStream ,
590
578
variants : & [ Variant ] ,
591
579
pc : & Ident ,
592
580
fty : & Ident ,
@@ -618,7 +606,7 @@ fn add_from_variants(
618
606
desc. to_owned ( )
619
607
} ;
620
608
621
- mod_items. push ( quote ! {
609
+ mod_items. extend ( quote ! {
622
610
#[ doc = #desc]
623
611
#[ derive( Clone , Copy , Debug , PartialEq ) ]
624
612
#repr
@@ -635,7 +623,7 @@ fn add_from_variants(
635
623
}
636
624
637
625
fn derive_from_base (
638
- mod_items : & mut Vec < TokenStream > ,
626
+ mod_items : & mut TokenStream ,
639
627
base : & Base ,
640
628
pc : & Ident ,
641
629
base_pc : & Ident ,
@@ -648,7 +636,7 @@ fn derive_from_base(
648
636
let pmod_ = Ident :: new ( & pmod_, span) ;
649
637
let rmod_ = Ident :: new ( & rmod_, span) ;
650
638
651
- mod_items. push ( quote ! {
639
+ mod_items. extend ( quote ! {
652
640
#[ doc = #desc]
653
641
pub type #pc =
654
642
crate :: #pmod_:: #rmod_:: #base_pc;
@@ -657,13 +645,13 @@ fn derive_from_base(
657
645
let mod_ = register. to_sanitized_snake_case ( ) ;
658
646
let mod_ = Ident :: new ( & mod_, span) ;
659
647
660
- mod_items. push ( quote ! {
648
+ mod_items. extend ( quote ! {
661
649
#[ doc = #desc]
662
650
pub type #pc =
663
651
super :: #mod_:: #base_pc;
664
652
} ) ;
665
653
} else {
666
- mod_items. push ( quote ! {
654
+ mod_items. extend ( quote ! {
667
655
#[ doc = #desc]
668
656
pub type #pc = #base_pc;
669
657
} ) ;
0 commit comments