Skip to content

Commit

Permalink
Don't clone words before joining them
Browse files Browse the repository at this point in the history
  • Loading branch information
triarius committed Sep 28, 2024
1 parent 6bdcda7 commit 4fc398e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/passphrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub fn new<T: Rng>(
num_words: usize,
separator: &str,
) -> Result<String> {
use itertools::Itertools;

if words.len() < num_words {
return Err(eyre!(
"Your dictionary only has {} suitable words, but you asked for {} words.",
Expand All @@ -20,10 +22,7 @@ pub fn new<T: Rng>(
words.swap(i, j);
});

Ok((0..num_words)
.map(|i| words[i].clone())
.collect::<Vec<_>>()
.join(separator))
Ok((0..num_words).map(|i| &words[i]).join(separator))
}

#[cfg(test)]
Expand Down

0 comments on commit 4fc398e

Please sign in to comment.