1
1
#![ allow( clippy:: useless_conversion) ]
2
2
3
- use super :: mystd:: ffi:: { OsStr , OsString } ;
3
+ use super :: mystd:: ffi:: OsStr ;
4
4
use super :: mystd:: fs;
5
- use super :: mystd:: os:: unix:: ffi:: { OsStrExt , OsStringExt } ;
5
+ use super :: mystd:: os:: unix:: ffi:: OsStrExt ;
6
6
use super :: mystd:: path:: { Path , PathBuf } ;
7
7
use super :: Either ;
8
8
use super :: { gimli, Context , Endian , EndianSlice , Mapping , Stash } ;
9
+ use alloc:: str:: String ;
9
10
use alloc:: sync:: Arc ;
10
11
use alloc:: vec:: Vec ;
11
12
use core:: convert:: { TryFrom , TryInto } ;
@@ -433,25 +434,17 @@ fn locate_build_id(build_id: &[u8]) -> Option<PathBuf> {
433
434
}
434
435
435
436
let mut path =
436
- Vec :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
437
+ String :: with_capacity ( BUILD_ID_PATH . len ( ) + BUILD_ID_SUFFIX . len ( ) + build_id. len ( ) * 2 + 1 ) ;
437
438
path. extend ( BUILD_ID_PATH ) ;
438
- path. push ( hex ( build_id[ 0 ] >> 4 ) ) ;
439
- path. push ( hex ( build_id[ 0 ] & 0xf ) ) ;
440
- path. push ( b '/') ;
439
+ path. push ( char :: from_digit ( ( build_id[ 0 ] >> 4 ) as u32 , 16 ) ? ) ;
440
+ path. push ( char :: from_digit ( ( build_id[ 0 ] & 0xf ) as u32 , 16 ) ? ) ;
441
+ path. push ( '/' ) ;
441
442
for byte in & build_id[ 1 ..] {
442
- path. push ( hex ( byte >> 4 ) ) ;
443
- path. push ( hex ( byte & 0xf ) ) ;
443
+ path. push ( char :: from_digit ( ( byte >> 4 ) as u32 , 16 ) ? ) ;
444
+ path. push ( char :: from_digit ( ( byte & 0xf ) as u32 , 16 ) ? ) ;
444
445
}
445
446
path. extend ( BUILD_ID_SUFFIX ) ;
446
- Some ( PathBuf :: from ( OsString :: from_vec ( path) ) )
447
- }
448
-
449
- fn hex ( byte : u8 ) -> u8 {
450
- if byte < 10 {
451
- b'0' + byte
452
- } else {
453
- b'a' + byte - 10
454
- }
447
+ Some ( PathBuf :: from ( path) )
455
448
}
456
449
457
450
/// Locate a file specified in a `.gnu_debuglink` section.
@@ -468,9 +461,8 @@ fn hex(byte: u8) -> u8 {
468
461
fn locate_debuglink ( path : & Path , filename : & [ u8 ] ) -> Option < PathBuf > {
469
462
let path = fs:: canonicalize ( path) . ok ( ) ?;
470
463
let parent = path. parent ( ) ?;
471
- let mut f = PathBuf :: from ( OsString :: with_capacity (
472
- DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ,
473
- ) ) ;
464
+ let mut f =
465
+ PathBuf :: with_capacity ( DEBUG_PATH . len ( ) + parent. as_os_str ( ) . len ( ) + filename. len ( ) + 2 ) ;
474
466
let filename = Path :: new ( OsStr :: from_bytes ( filename) ) ;
475
467
476
468
// Try "/parent/filename" if it differs from "path"
@@ -481,9 +473,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
481
473
}
482
474
483
475
// Try "/parent/.debug/filename"
484
- let mut s = OsString :: from ( f) ;
485
- s. clear ( ) ;
486
- f = PathBuf :: from ( s) ;
476
+ f. clear ( ) ;
487
477
f. push ( parent) ;
488
478
f. push ( ".debug" ) ;
489
479
f. push ( filename) ;
@@ -493,9 +483,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
493
483
494
484
if debug_path_exists ( ) {
495
485
// Try "/usr/lib/debug/parent/filename"
496
- let mut s = OsString :: from ( f) ;
497
- s. clear ( ) ;
498
- f = PathBuf :: from ( s) ;
486
+ f. clear ( ) ;
499
487
f. push ( OsStr :: from_bytes ( DEBUG_PATH ) ) ;
500
488
f. push ( parent. strip_prefix ( "/" ) . unwrap ( ) ) ;
501
489
f. push ( filename) ;
0 commit comments