Reduce allocations

This commit is contained in:
eraden 2021-10-12 22:45:37 +02:00
parent 4e5f2101df
commit a4c7f916be

View File

@ -31,9 +31,11 @@ pub fn view(model: &Model, modal: &AddIssueModal) -> Node<Msg> {
let issue_type_field = issue_type_field(modal); let issue_type_field = issue_type_field(modal);
let mut form = StyledForm { let mut form = StyledForm {
heading: issue_type.form_label(), heading: issue_type.form_label(),
fields: vec![issue_type_field, crate::shared::divider()], fields: Vec::with_capacity(10),
..Default::default() ..Default::default()
}; };
form.fields
.extend_from_slice(&[issue_type_field, crate::shared::divider()]);
match issue_type { match issue_type {
Type::Epic => { Type::Epic => {
@ -63,25 +65,19 @@ pub fn view(model: &Model, modal: &AddIssueModal) -> Node<Msg> {
} }
.render(); .render();
form.fields.push(name_field); form.fields.extend_from_slice(&[name_field, starts, end])
form.fields.push(starts);
form.fields.push(end)
} }
Type::Task | Type::Story | Type::Bug => { Type::Task | Type::Story | Type::Bug => {
let short_summary_field = short_summary_field(modal); form.fields.extend_from_slice(&[
let description_field = description_field(); short_summary_field(modal),
let reporter_field = reporter_field(model, modal); description_field(),
let assignees_field = assignees_field(model, modal); reporter_field(model, modal),
let issue_priority_field = issue_priority_field(modal); assignees_field(model, modal),
let epic_field = issue_priority_field(modal),
epic_field(model, modal, FieldId::AddIssueModal(IssueFieldId::EpicName)); ]);
if let Some(field) =
form.fields.push(short_summary_field); epic_field(model, modal, FieldId::AddIssueModal(IssueFieldId::EpicName))
form.fields.push(description_field); {
form.fields.push(reporter_field);
form.fields.push(assignees_field);
form.fields.push(issue_priority_field);
if let Some(field) = epic_field {
form.fields.push(field); form.fields.push(field);
} }
} }
@ -105,9 +101,9 @@ pub fn view(model: &Model, modal: &AddIssueModal) -> Node<Msg> {
..Default::default() ..Default::default()
} }
.render(); .render();
let actions = div![attrs![At::Class => "actions"], submit, cancel];
form.fields.push(actions); form.fields
.push(div![attrs![At::Class => "actions"], submit, cancel]);
StyledModal { StyledModal {
class_list: "addIssue", class_list: "addIssue",