File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ impl<'a> DecodeValue<'a> for BytesOwned {
6969 // Parse constructed indefinite length data
7070 // TODO(tarcieri): extract this somewhere reusable
7171 let mut bytes = Vec :: with_capacity ( header. length . try_into ( ) ?) ;
72+ let mut offset = 0 ;
7273
7374 while !reader. is_finished ( ) {
7475 let h = Header :: decode ( reader) ?;
@@ -79,9 +80,11 @@ impl<'a> DecodeValue<'a> for BytesOwned {
7980 return Err ( reader. error ( ErrorKind :: IndefiniteLength ) ) ;
8081 }
8182
82- // TODO(tarcieri): more efficient reader
83- let mut chunk = reader. read_vec ( h. length ) ?;
84- bytes. append ( & mut chunk) ;
83+ // Add enough zeroes into the `Vec` to store the chunk
84+ let l = usize:: try_from ( h. length ) ?;
85+ bytes. extend ( core:: iter:: repeat_n ( 0 , l) ) ;
86+ reader. read_into ( & mut bytes[ offset..( offset + l) ] ) ?;
87+ offset += l;
8588 }
8689
8790 return Self :: new ( bytes) ;
You can’t perform that action at this time.
0 commit comments