1- use super :: mystd:: ffi:: { OsStr , OsString } ;
1+ use super :: mystd:: ffi:: OsStr ;
22use super :: mystd:: fs;
3- use super :: mystd:: os:: unix:: ffi:: { OsStrExt , OsStringExt } ;
3+ use super :: mystd:: os:: unix:: ffi:: OsStrExt ;
44use super :: mystd:: path:: { Path , PathBuf } ;
55use super :: Either ;
66use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash } ;
7+ use alloc:: str:: String ;
78use alloc:: sync:: Arc ;
89use alloc:: vec:: Vec ;
910use core:: convert:: { TryFrom , TryInto } ;
@@ -346,25 +347,17 @@ fn locate_build_id(build_id: &[u8]) -> Option<PathBuf> {
346347 }
347348
348349 let mut path =
349- Vec :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
350+ String :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
350351 path. extend ( BUILD_ID_PATH ) ;
351- path. push ( hex ( build_id[ 0 ] >> 4 ) ) ;
352- path. push ( hex ( build_id[ 0 ] & 0xf ) ) ;
353- path. push ( b '/') ;
352+ path. push ( char :: from_digit ( ( build_id[ 0 ] >> 4 ) as u32 , 16 ) ? ) ;
353+ path. push ( char :: from_digit ( ( build_id[ 0 ] & 0xf ) as u32 , 16 ) ? ) ;
354+ path. push ( '/' ) ;
354355 for byte in & build_id[ 1 ..] {
355- path. push ( hex ( byte >> 4 ) ) ;
356- path. push ( hex ( byte & 0xf ) ) ;
356+ path. push ( char :: from_digit ( ( byte >> 4 ) as u32 , 16 ) ? ) ;
357+ path. push ( char :: from_digit ( ( byte & 0xf ) as u32 , 16 ) ? ) ;
357358 }
358359 path. extend ( BUILD_ID_SUFFIX ) ;
359- Some ( PathBuf :: from ( OsString :: from_vec ( path) ) )
360- }
361-
362- fn hex ( byte : u8 ) -> u8 {
363- if byte < 10 {
364- b'0' + byte
365- } else {
366- b'a' + byte - 10
367- }
360+ Some ( PathBuf :: from ( path) )
368361}
369362
370363/// Locate a file specified in a `.gnu_debuglink` section.
@@ -381,9 +374,8 @@ fn hex(byte: u8) -> u8 {
381374fn locate_debuglink ( path : & Path , filename : & [ u8 ] ) -> Option < PathBuf > {
382375 let path = fs:: canonicalize ( path) . ok ( ) ?;
383376 let parent = path. parent ( ) ?;
384- let mut f = PathBuf :: from ( OsString :: with_capacity (
385- DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ,
386- ) ) ;
377+ let mut f =
378+ PathBuf :: with_capacity ( DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ) ;
387379 let filename = Path :: new ( OsStr :: from_bytes ( filename) ) ;
388380
389381 // Try "/parent/filename" if it differs from "path"
@@ -394,9 +386,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
394386 }
395387
396388 // Try "/parent/.debug/filename"
397- let mut s = OsString :: from ( f) ;
398- s. clear ( ) ;
399- f = PathBuf :: from ( s) ;
389+ f. clear ( ) ;
400390 f. push ( parent) ;
401391 f. push ( ".debug" ) ;
402392 f. push ( filename) ;
@@ -406,9 +396,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
406396
407397 if debug_path_exists ( ) {
408398 // Try "/usr/lib/debug/parent/filename"
409- let mut s = OsString :: from ( f) ;
410- s. clear ( ) ;
411- f = PathBuf :: from ( s) ;
399+ f. clear ( ) ;
412400 f. push ( OsStr :: from_bytes ( DEBUG_PATH ) ) ;
413401 f. push ( parent. strip_prefix ( "/" ) . unwrap ( ) ) ;
414402 f. push ( filename) ;
0 commit comments