various: reduce allocations where available

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I517d855b14c015569a325deb64948f3b6a6a6964
This commit is contained in:
raf 2025-11-17 17:55:10 +03:00
commit 2ad765ef98
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
5 changed files with 125 additions and 65 deletions

View file

@ -1,4 +1,4 @@
use std::{io, mem::MaybeUninit};
use std::{fmt::Write, io, mem::MaybeUninit};
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_current() -> Result<String, io::Error> {
@ -16,21 +16,21 @@ pub fn get_current() -> Result<String, io::Error> {
let mut result = String::with_capacity(32);
if days > 0 {
result.push_str(&days.to_string());
let _ = write!(result, "{days}");
result.push_str(if days == 1 { " day" } else { " days" });
}
if hours > 0 {
if !result.is_empty() {
result.push_str(", ");
}
result.push_str(&hours.to_string());
let _ = write!(result, "{hours}");
result.push_str(if hours == 1 { " hour" } else { " hours" });
}
if minutes > 0 {
if !result.is_empty() {
result.push_str(", ");
}
result.push_str(&minutes.to_string());
let _ = write!(result, "{minutes}");
result.push_str(if minutes == 1 { " minute" } else { " minutes" });
}
if result.is_empty() {