@@ -307,10 +307,9 @@ impl std::fmt::Display for DisassemblyTextLine {
307
307
}
308
308
309
309
impl From < Vec < InstructionTextToken > > for DisassemblyTextLine {
310
- fn from ( mut tokens : Vec < InstructionTextToken > ) -> Self {
311
- tokens. shrink_to_fit ( ) ;
310
+ fn from ( tokens : Vec < InstructionTextToken > ) -> Self {
311
+ let mut tokens: Box < [ _ ] > = tokens . into ( ) ;
312
312
313
- assert ! ( tokens. len( ) == tokens. capacity( ) ) ;
314
313
// TODO: let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nightly feature
315
314
let tokens_pointer = tokens. as_mut_ptr ( ) ;
316
315
let tokens_len = tokens. len ( ) ;
@@ -345,14 +344,11 @@ impl From<Vec<InstructionTextToken>> for DisassemblyTextLine {
345
344
346
345
impl From < & Vec < & str > > for DisassemblyTextLine {
347
346
fn from ( string_tokens : & Vec < & str > ) -> Self {
348
- let mut tokens: Vec < BNInstructionTextToken > = Vec :: with_capacity ( string_tokens. len ( ) ) ;
349
- tokens. extend (
350
- string_tokens. iter ( ) . map ( |& token| {
351
- InstructionTextToken :: new ( token, InstructionTextTokenContents :: Text ) . 0
352
- } ) ,
353
- ) ;
354
-
355
- assert ! ( tokens. len( ) == tokens. capacity( ) ) ;
347
+ let mut tokens: Box < [ BNInstructionTextToken ] > = string_tokens
348
+ . iter ( )
349
+ . map ( |& token| InstructionTextToken :: new ( token, InstructionTextTokenContents :: Text ) . 0 )
350
+ . collect ( ) ;
351
+
356
352
// let (tokens_pointer, tokens_len, _) = unsafe { tokens.into_raw_parts() }; // Can't use for now...still a rust nighly feature
357
353
let tokens_pointer = tokens. as_mut_ptr ( ) ;
358
354
let tokens_len = tokens. len ( ) ;
@@ -416,8 +412,9 @@ impl Default for DisassemblyTextLine {
416
412
417
413
impl Drop for DisassemblyTextLine {
418
414
fn drop ( & mut self ) {
419
- unsafe {
420
- Vec :: from_raw_parts ( self . 0 . tokens , self . 0 . count , self . 0 . count ) ;
415
+ if !self . 0 . tokens . is_null ( ) {
416
+ let ptr = core:: ptr:: slice_from_raw_parts_mut ( self . 0 . tokens , self . 0 . count ) ;
417
+ let _ = unsafe { Box :: from_raw ( ptr) } ;
421
418
}
422
419
}
423
420
}
0 commit comments