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.
This commit is contained in:
raf 2024-12-19 18:27:25 +03:00
parent e19abcedae
commit fd18e9d244
No known key found for this signature in database
GPG key ID: EED98D11B85A2819

View file

@ -21,7 +21,13 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
for line in reader.lines() {
let line = line?;
if let Some(pretty_name) = line.strip_prefix("PRETTY_NAME=") {
return Ok(pretty_name.trim_matches('"').to_string());
if let Some(trimmed) = pretty_name
.strip_prefix('"')
.and_then(|s| s.strip_suffix('"'))
{
return Ok(trimmed.to_string());
}
return Ok(pretty_name.to_string());
}
}