Skip to content

Commit fd18e9d

Browse files
committed
release: conditionally improve performance for get_os_pretty_name
It is difficult to get completely accurate benchmarks, given how small the numbers we are dealing with are, but this seems to point at an overall trend of *slightly* faster execution. The change minimizes unnecessary memory allocations and string manipulations, to help ensure more performant line reading and immediate return upon finding the PRETTY_NAME without additional, redundant operations.
1 parent e19abce commit fd18e9d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/release.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
2121
for line in reader.lines() {
2222
let line = line?;
2323
if let Some(pretty_name) = line.strip_prefix("PRETTY_NAME=") {
24-
return Ok(pretty_name.trim_matches('"').to_string());
24+
if let Some(trimmed) = pretty_name
25+
.strip_prefix('"')
26+
.and_then(|s| s.strip_suffix('"'))
27+
{
28+
return Ok(trimmed.to_string());
29+
}
30+
return Ok(pretty_name.to_string());
2531
}
2632
}
2733

0 commit comments

Comments
 (0)