Skip to content
Snippets Groups Projects
Commit 4d975710 authored by Martin Larralde's avatar Martin Larralde
Browse files

Avoid initialization when allocating new buffer in `EncodedSequence::encode`

parent 6830cdb6
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,8 @@ pub trait Encode<A: Alphabet> {
/// Encode the given sequence into a vector of symbols.
fn encode<S: AsRef<[u8]>>(&self, seq: S) -> Result<Vec<A::Symbol>, InvalidSymbol> {
let s = seq.as_ref();
let mut buffer = vec![A::default_symbol(); s.len()];
let mut buffer = Vec::with_capacity(s.len());
unsafe { buffer.set_len(s.len()) };
match self.encode_into(s, &mut buffer) {
Ok(_) => Ok(buffer),
Err(e) => Err(e),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment