diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-08-26 00:22:16 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-08-26 00:54:07 +0300 |
commit | e349882ea7d1c5bbc3d08faf9c08758393891ff1 (patch) | |
tree | 89de93a1a0b84ca209df786bd8a2a023b7beec13 /melib/src/email/parser.rs | |
parent | 14663e46b9be8bbb86e36541b8cfb9c5efc341c2 (diff) |
melib/email/parser: use SmallVec in encoded words
Diffstat (limited to 'melib/src/email/parser.rs')
-rw-r--r-- | melib/src/email/parser.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 7af3dd1b..1e85835c 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -30,6 +30,7 @@ use nom::{ number::complete::le_u8, sequence::{delimited, pair, preceded, separated_pair, terminated}, }; +use smallvec::SmallVec; use std::borrow::Cow; #[derive(Debug, Eq, PartialEq)] @@ -1116,7 +1117,7 @@ pub mod encodings { //eat_separator!()); } - pub fn encoded_word_list(input: &[u8]) -> IResult<&[u8], Vec<u8>> { + pub fn encoded_word_list(input: &[u8]) -> IResult<&[u8], SmallVec<[u8; 64]>> { let (input, list) = separated_nonempty_list(space, encoded_word)(input)?; let list_len = list.iter().fold(0, |mut acc, x| { acc += x.len(); @@ -1125,19 +1126,19 @@ pub mod encodings { Ok(( input, list.iter() - .fold(Vec::with_capacity(list_len), |mut acc, x| { - acc.append(&mut x.clone()); + .fold(SmallVec::with_capacity(list_len), |mut acc, x| { + acc.extend(x.into_iter().cloned()); acc }), )) } - pub fn ascii_token(input: &[u8]) -> IResult<&[u8], Vec<u8>> { + pub fn ascii_token(input: &[u8]) -> IResult<&[u8], SmallVec<[u8; 64]>> { let (input, word) = alt(( terminated(take_until(" =?"), peek(preceded(tag(b" "), encoded_word))), take_while(|_| true), ))(input)?; - Ok((input, word.to_vec())) + Ok((input, SmallVec::from(word))) } pub fn phrase( |