diff options
| author | Rubens Brandao <git@rubens.io> | 2024-04-11 06:29:03 -0300 |
|---|---|---|
| committer | Rubens Brandao <git@rubens.io> | 2024-04-11 06:29:03 -0300 |
| commit | 9b0175bb0c116e22f00d6a3137c52b136be04bf7 (patch) | |
| tree | a77a249125e9a43a6342330d6844c33fbd3bfab0 /rust/src | |
| parent | 16fc31044f3b202200a6f03a538cda5f985bbecb (diff) | |
replace Vec<T> with Box<[T]> where capacity eq to len
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/disassembly.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs index f213fa0e..65606ef6 100644 --- a/rust/src/disassembly.rs +++ b/rust/src/disassembly.rs @@ -307,10 +307,9 @@ impl std::fmt::Display for DisassemblyTextLine { } impl From<Vec<InstructionTextToken>> for DisassemblyTextLine { - fn from(mut tokens: Vec<InstructionTextToken>) -> Self { - tokens.shrink_to_fit(); + fn from(tokens: Vec<InstructionTextToken>) -> Self { + let mut tokens: Box<[_]> = tokens.into(); - assert!(tokens.len() == tokens.capacity()); // TODO: let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nightly feature let tokens_pointer = tokens.as_mut_ptr(); let tokens_len = tokens.len(); @@ -345,14 +344,11 @@ impl From<Vec<InstructionTextToken>> for DisassemblyTextLine { impl From<&Vec<&str>> for DisassemblyTextLine { fn from(string_tokens: &Vec<&str>) -> Self { - let mut tokens: Vec<BNInstructionTextToken> = Vec::with_capacity(string_tokens.len()); - tokens.extend( - string_tokens.iter().map(|&token| { - InstructionTextToken::new(token, InstructionTextTokenContents::Text).0 - }), - ); + let mut tokens: Box<[BNInstructionTextToken]> = string_tokens + .iter() + .map(|&token| InstructionTextToken::new(token, InstructionTextTokenContents::Text).0) + .collect(); - assert!(tokens.len() == tokens.capacity()); // let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nighly feature let tokens_pointer = tokens.as_mut_ptr(); let tokens_len = tokens.len(); |
