1
- use super :: mystd:: ffi:: { OsStr , OsString } ;
1
+ use super :: mystd:: ffi:: OsStr ;
2
2
use super :: mystd:: fs;
3
- use super :: mystd:: os:: unix:: ffi:: { OsStrExt , OsStringExt } ;
3
+ use super :: mystd:: os:: unix:: ffi:: OsStrExt ;
4
4
use super :: mystd:: path:: { Path , PathBuf } ;
5
5
use super :: Either ;
6
6
use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash } ;
7
+ use alloc:: str:: String ;
7
8
use alloc:: sync:: Arc ;
8
9
use alloc:: vec:: Vec ;
9
10
use core:: convert:: { TryFrom , TryInto } ;
@@ -346,25 +347,17 @@ fn locate_build_id(build_id: &[u8]) -> Option<PathBuf> {
346
347
}
347
348
348
349
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 ) ;
350
351
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 ( '/' ) ;
354
355
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 ) ? ) ;
357
358
}
358
359
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) )
368
361
}
369
362
370
363
/// Locate a file specified in a `.gnu_debuglink` section.
@@ -381,9 +374,8 @@ fn hex(byte: u8) -> u8 {
381
374
fn locate_debuglink ( path : & Path , filename : & [ u8 ] ) -> Option < PathBuf > {
382
375
let path = fs:: canonicalize ( path) . ok ( ) ?;
383
376
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 ) ;
387
379
let filename = Path :: new ( OsStr :: from_bytes ( filename) ) ;
388
380
389
381
// Try "/parent/filename" if it differs from "path"
@@ -394,9 +386,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
394
386
}
395
387
396
388
// Try "/parent/.debug/filename"
397
- let mut s = OsString :: from ( f) ;
398
- s. clear ( ) ;
399
- f = PathBuf :: from ( s) ;
389
+ f. clear ( ) ;
400
390
f. push ( parent) ;
401
391
f. push ( ".debug" ) ;
402
392
f. push ( filename) ;
@@ -406,9 +396,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
406
396
407
397
if debug_path_exists ( ) {
408
398
// Try "/usr/lib/debug/parent/filename"
409
- let mut s = OsString :: from ( f) ;
410
- s. clear ( ) ;
411
- f = PathBuf :: from ( s) ;
399
+ f. clear ( ) ;
412
400
f. push ( OsStr :: from_bytes ( DEBUG_PATH ) ) ;
413
401
f. push ( parent. strip_prefix ( "/" ) . unwrap ( ) ) ;
414
402
f. push ( filename) ;
0 commit comments