@@ -9,6 +9,7 @@ use core::slice;
99use core:: str:: { self , FromStr } ;
1010use uguid:: Guid ;
1111
12+ use crate :: mem:: AlignedBuffer ;
1213use crate :: proto:: device_path:: DevicePath ;
1314use crate :: { CStr16 , Char16 } ;
1415
@@ -25,7 +26,7 @@ pub struct ConfigurationStringIter<'a> {
2526}
2627
2728impl < ' a > ConfigurationStringIter < ' a > {
28- /// Creates a new splitter instance for a given configuration string buffer .
29+ /// Creates a new splitter instance for a given configuration string.
2930 #[ must_use]
3031 pub const fn new ( bfr : & ' a str ) -> Self {
3132 Self { bfr }
@@ -169,11 +170,15 @@ impl ConfigurationString {
169170 if data. len ( ) % 2 != 0 {
170171 return None ;
171172 }
172- let mut data: Vec < _ > = Self :: parse_bytes_from_hex ( data) . collect ( ) ;
173- data. chunks_exact_mut ( 2 ) . for_each ( |c| c. swap ( 0 , 1 ) ) ;
174- data. extend_from_slice ( & [ 0 , 0 ] ) ;
173+ let size_bytes = data. len ( ) / 2 + 2 ; // includes \0 terminator
174+ let size_chars = size_bytes / 2 ;
175+ let mut bfr = AlignedBuffer :: from_size_align ( size_bytes, 2 ) . ok ( ) ?;
176+ bfr. copy_from_iter ( Self :: parse_bytes_from_hex ( data) . chain ( [ 0 , 0 ] ) ) ;
177+ bfr. as_slice_mut ( )
178+ . chunks_exact_mut ( 2 )
179+ . for_each ( |c| c. swap ( 0 , 1 ) ) ;
175180 let data: & [ Char16 ] =
176- unsafe { slice:: from_raw_parts ( data . as_slice ( ) . as_ptr ( ) . cast ( ) , data . len ( ) / 2 ) } ;
181+ unsafe { slice:: from_raw_parts ( bfr . as_slice ( ) . as_ptr ( ) . cast ( ) , size_chars ) } ;
177182 Some ( CStr16 :: from_char16_with_nul ( data) . ok ( ) ?. to_string ( ) )
178183 }
179184
0 commit comments