mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-12-08 14:03:51 +00:00
various: reduce allocations where available
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I517d855b14c015569a325deb64948f3b6a6a6964
This commit is contained in:
parent
325ec69024
commit
2ad765ef98
5 changed files with 125 additions and 65 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue