Skip to content

Commit 5a484b0

Browse files
committed
more cold functions
1 parent 9dd03a9 commit 5a484b0

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/desktop.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::ffi::CStr;
22

3-
#[inline]
4-
#[cold]
5-
const fn unknown() -> &'static str { "Unknown" }
3+
use crate::unknown;
64

75
#[must_use]
86
#[cfg_attr(feature = "hotpath", hotpath::measure)]

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ pub mod uptime;
88

99
use std::{io, mem::MaybeUninit};
1010

11+
#[inline]
12+
#[cold]
13+
pub const fn unknown() -> &'static str { "Unknown" }
14+
1115
#[inline]
1216
#[cold]
1317
pub fn last_os_error<T>() -> io::Result<T> {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod uptime;
88

99
use std::io::{self, Cursor, Write};
1010

11-
pub use microfetch_lib::{UtsName, last_os_error};
11+
pub use microfetch_lib::{UtsName, last_os_error, unknown};
1212

1313
use crate::{
1414
desktop::get_desktop_info,

src/release.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::io;
22

3-
use crate::{UtsName, syscall::read_file_fast};
3+
use crate::{syscall::read_file_fast, unknown, UtsName};
44

55
#[must_use]
66
#[cfg_attr(feature = "hotpath", hotpath::measure)]
77
pub fn get_system_info(utsname: &UtsName) -> String {
8-
let sysname = utsname.sysname().to_str().unwrap_or("Unknown");
9-
let release = utsname.release().to_str().unwrap_or("Unknown");
10-
let machine = utsname.machine().to_str().unwrap_or("Unknown");
8+
let sysname = utsname.sysname().to_str().unwrap_or_else(|_| unknown());
9+
let release = utsname.release().to_str().unwrap_or_else(|_| unknown());
10+
let machine = utsname.machine().to_str().unwrap_or_else(|_| unknown());
1111

1212
// Pre-allocate capacity: sysname + " " + release + " (" + machine + ")"
1313
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> {
7171
offset += line_end + 1;
7272
}
7373

74-
Ok("Unknown".to_owned())
74+
Ok(unknown().to_owned())
7575
}

0 commit comments

Comments
 (0)