mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-12-13 16:11:01 +00:00
more cold functions
This commit is contained in:
parent
9dd03a900b
commit
5a484b0769
4 changed files with 11 additions and 9 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue