From fd18e9d24467f197c08a9d3498ce5b611ec8bb80 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 19 Dec 2024 18:27:25 +0300 Subject: [PATCH] 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. --- src/release.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/release.rs b/src/release.rs index 3f38977..c0036fb 100644 --- a/src/release.rs +++ b/src/release.rs @@ -21,7 +21,13 @@ pub fn get_os_pretty_name() -> Result { 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()); } }