Skip to content

Commit 7a9ef9f

Browse files
committed
De-Vec-torized mod_items TokenStream
Signed-off-by: Daniel Egger <[email protected]>
1 parent ab03e5e commit 7a9ef9f

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/generate/register.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn render(
4242
.as_ref(),
4343
);
4444

45-
let mut mod_items = vec![];
45+
let mut mod_items = TokenStream::new();
4646
let mut r_impl_items = vec![];
4747
let mut w_impl_items = vec![];
4848
let mut methods = vec![];
@@ -52,7 +52,7 @@ pub fn render(
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,29 @@ 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

139135
for item in w_impl_items {
140-
mod_items.push(quote! {
136+
mod_items.extend(quote! {
141137
#item
142138
});
143139
}
144140

145-
mod_items.push(quote! {
141+
mod_items.extend(quote! {
146142
#close
147143
});
148144
}
@@ -219,7 +215,7 @@ pub fn fields(
219215
rty: &Ident,
220216
reset_value: Option<u64>,
221217
access: Access,
222-
mod_items: &mut Vec<TokenStream>,
218+
mod_items: &mut TokenStream,
223219
r_impl_items: &mut Vec<TokenStream>,
224220
w_impl_items: &mut Vec<TokenStream>,
225221
) -> Result<()> {
@@ -311,7 +307,7 @@ pub fn fields(
311307
derive_from_base(mod_items, &base, &pc_r, &base_pc_r, &description);
312308

313309
let doc = format!("Reader of field `{}`", f.name);
314-
mod_items.push(quote! {
310+
mod_items.extend(quote! {
315311
#[doc = #doc]
316312
pub type #_pc_r = crate::R<#fty, #pc_r>;
317313
});
@@ -394,7 +390,7 @@ pub fn fields(
394390
}
395391

396392
let doc = format!("Reader of field `{}`", f.name);
397-
mod_items.push(quote! {
393+
mod_items.extend(quote! {
398394
#[doc = #doc]
399395
pub type #_pc_r = crate::R<#fty, #pc_r>;
400396
impl #_pc_r {
@@ -412,7 +408,7 @@ pub fn fields(
412408
});
413409

414410
let doc = format!("Reader of field `{}`", f.name);
415-
mod_items.push(quote! {
411+
mod_items.extend(quote! {
416412
#[doc = #doc]
417413
pub type #_pc_r = crate::R<#fty, #fty>;
418414
})
@@ -507,7 +503,7 @@ pub fn fields(
507503
});
508504

509505
let doc = format!("Write proxy for field `{}`", f.name);
510-
mod_items.push(quote! {
506+
mod_items.extend(quote! {
511507
#[doc = #doc]
512508
pub struct #_pc_w<'a> {
513509
w: &'a mut W,
@@ -586,7 +582,7 @@ impl Variant {
586582
}
587583

588584
fn add_from_variants(
589-
mod_items: &mut Vec<TokenStream>,
585+
mod_items: &mut TokenStream,
590586
variants: &[Variant],
591587
pc: &Ident,
592588
fty: &Ident,
@@ -618,7 +614,7 @@ fn add_from_variants(
618614
desc.to_owned()
619615
};
620616

621-
mod_items.push(quote! {
617+
mod_items.extend(quote! {
622618
#[doc = #desc]
623619
#[derive(Clone, Copy, Debug, PartialEq)]
624620
#repr
@@ -635,7 +631,7 @@ fn add_from_variants(
635631
}
636632

637633
fn derive_from_base(
638-
mod_items: &mut Vec<TokenStream>,
634+
mod_items: &mut TokenStream,
639635
base: &Base,
640636
pc: &Ident,
641637
base_pc: &Ident,
@@ -648,7 +644,7 @@ fn derive_from_base(
648644
let pmod_ = Ident::new(&pmod_, span);
649645
let rmod_ = Ident::new(&rmod_, span);
650646

651-
mod_items.push(quote! {
647+
mod_items.extend(quote! {
652648
#[doc = #desc]
653649
pub type #pc =
654650
crate::#pmod_::#rmod_::#base_pc;
@@ -657,13 +653,13 @@ fn derive_from_base(
657653
let mod_ = register.to_sanitized_snake_case();
658654
let mod_ = Ident::new(&mod_, span);
659655

660-
mod_items.push(quote! {
656+
mod_items.extend(quote! {
661657
#[doc = #desc]
662658
pub type #pc =
663659
super::#mod_::#base_pc;
664660
});
665661
} else {
666-
mod_items.push(quote! {
662+
mod_items.extend(quote! {
667663
#[doc = #desc]
668664
pub type #pc = #base_pc;
669665
});

0 commit comments

Comments
 (0)