From 51fcf2efdaae8bdd5270cfe64de1522eadd1775f Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Mon, 2 Sep 2024 22:23:01 -0600 Subject: Refactor Verse::clause() There is no reason to return an option for clause(), since it makes us perform a match twice, and since a blank vector is perfectly acceptable in all cases where the verse at hand may not have a clause. Signed-off-by: Rory Dudley --- src/poem/elements/verse.rs | 8 ++++---- src/poem/elements/verse/logic.rs | 2 +- src/poem/read.rs | 6 ++---- 3 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/poem') diff --git a/src/poem/elements/verse.rs b/src/poem/elements/verse.rs index 1c5bcc1..9ebd31d 100644 --- a/src/poem/elements/verse.rs +++ b/src/poem/elements/verse.rs @@ -140,11 +140,11 @@ impl Verse { /// Get the [Verse]'s clause /// /// Return program arguments, if they exist - pub fn clause(&self) -> Option> { + pub fn clause(&self) -> Vec { match self.stanza.len() { - 0 => None, - 1 => None, - _ => Some(self.stanza[1..].to_vec()), + 0 => vec![], + 1 => vec![], + _ => self.stanza[1..].to_vec(), } } diff --git a/src/poem/elements/verse/logic.rs b/src/poem/elements/verse/logic.rs index e7ed4df..41b736b 100644 --- a/src/poem/elements/verse/logic.rs +++ b/src/poem/elements/verse/logic.rs @@ -15,7 +15,7 @@ #[macro_export] macro_rules! incant { ($verb:expr, $command:expr, $out:expr, $pids:expr, $env:expr, $self:expr) => {{ - $command.args($self.clause().unwrap_or(vec![])); + $command.args($self.clause()); // Determine couplet status if $self.couplet == 1 { diff --git a/src/poem/read.rs b/src/poem/read.rs index 7f3ae32..99e9aa6 100644 --- a/src/poem/read.rs +++ b/src/poem/read.rs @@ -149,10 +149,8 @@ impl Appendable for Poem { lv.ep = verse.ep.clone(); lv.poems = verse.poems.clone(); lv.meter = verse.meter; - if verse.clause().is_some() { - for word in verse.clause().unwrap().iter() { - lv.stanza.push(word.to_string()); - } + for word in verse.clause().iter() { + lv.stanza.push(word.to_string()); } // Push verse(s) -- cgit v1.2.3