Skip to content

Commit

Permalink
perf: correct vector capacity to avoid realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlambson committed Aug 11, 2024
1 parent 932fe22 commit bf36129
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ fn generate(alphabet: Option<&str>, size: Option<usize>) -> PyResult<String> {
None => "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-".to_string(),
};
let size = size.unwrap_or(21);
let mut alphabet_vec = Vec::with_capacity(size); // Not sure what size this should be but this
// should guarantee no reallocs
let mut alphabet_vec = Vec::with_capacity(alphabet.chars().count());

let mut alphabet_len = 0;
for char in alphabet.chars() {
Expand Down

0 comments on commit bf36129

Please sign in to comment.