Skip to content

Commit 29e12b2

Browse files
authored
Two simplifications (#26)
* elf: avoid string copies in get_dynstr_by_tag() * Simplify VecRpath formatting
1 parent a87c3d1 commit 29e12b2

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/elf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub trait Properties {
287287
/// `VecRpath`
288288
fn has_runpath(&self) -> VecRpath;
289289
/// return the corresponding string from dynstrtab for a given `d_tag`
290-
fn get_dynstr_by_tag(&self, tag: u64) -> Option<String>;
290+
fn get_dynstr_by_tag(&self, tag: u64) -> Option<&str>;
291291
}
292292

293293
// readelf -s -W /lib/x86_64-linux-gnu/libc.so.6 | grep _chk
@@ -523,15 +523,15 @@ impl Properties for Elf<'_> {
523523
}
524524
VecRpath::new(vec![Rpath::None])
525525
}
526-
fn get_dynstr_by_tag(&self, tag: u64) -> Option<String> {
526+
fn get_dynstr_by_tag(&self, tag: u64) -> Option<&str> {
527527
if let Some(dynamic) = &self.dynamic {
528528
for dynamic in &dynamic.dyns {
529529
if dynamic.d_tag == tag {
530530
#[allow(clippy::cast_possible_truncation)]
531531
if let Some(name) =
532532
self.dynstrtab.get_at(dynamic.d_val as usize)
533533
{
534-
return Some(name.to_string());
534+
return Some(name);
535535
}
536536
}
537537
}

src/shared.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ impl fmt::Display for VecRpath {
3232
Rpath::None => s.push("None".to_string()),
3333
}
3434
}
35-
write!(f, "{}", s.join(":"))?;
36-
Ok(())
35+
write!(f, "{}", s.join(":"))
3736
}
3837
}
3938
#[cfg(feature = "color")]
@@ -46,7 +45,6 @@ impl fmt::Display for VecRpath {
4645
Rpath::None => s.push("None".green().to_string()),
4746
}
4847
}
49-
write!(f, "{}", s.join(":"))?;
50-
Ok(())
48+
write!(f, "{}", s.join(":"))
5149
}
5250
}

0 commit comments

Comments
 (0)