more cold functions

This commit is contained in:
poz 2025-12-12 22:58:10 +01:00
commit 5a484b0769
No known key found for this signature in database
4 changed files with 11 additions and 9 deletions

View file

@ -1,8 +1,6 @@
use std::ffi::CStr;
#[inline]
#[cold]
const fn unknown() -> &'static str { "Unknown" }
use crate::unknown;
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]

View file

@ -8,6 +8,10 @@ pub mod uptime;
use std::{io, mem::MaybeUninit};
#[inline]
#[cold]
pub const fn unknown() -> &'static str { "Unknown" }
#[inline]
#[cold]
pub fn last_os_error<T>() -> io::Result<T> {

View file

@ -8,7 +8,7 @@ mod uptime;
use std::io::{self, Cursor, Write};
pub use microfetch_lib::{UtsName, last_os_error};
pub use microfetch_lib::{UtsName, last_os_error, unknown};
use crate::{
desktop::get_desktop_info,

View file

@ -1,13 +1,13 @@
use std::io;
use crate::{UtsName, syscall::read_file_fast};
use crate::{syscall::read_file_fast, unknown, UtsName};
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_system_info(utsname: &UtsName) -> String {
let sysname = utsname.sysname().to_str().unwrap_or("Unknown");
let release = utsname.release().to_str().unwrap_or("Unknown");
let machine = utsname.machine().to_str().unwrap_or("Unknown");
let sysname = utsname.sysname().to_str().unwrap_or_else(|_| unknown());
let release = utsname.release().to_str().unwrap_or_else(|_| unknown());
let machine = utsname.machine().to_str().unwrap_or_else(|_| unknown());
// Pre-allocate capacity: sysname + " " + release + " (" + machine + ")"
let capacity = sysname.len() + 1 + release.len() + 2 + machine.len() + 1;
@ -71,5 +71,5 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
offset += line_end + 1;
}
Ok("Unknown".to_owned())
Ok(unknown().to_owned())
}