diff --git a/rust/examples/bench.rs b/rust/examples/bench.rs index 12d1282..4153a75 100644 --- a/rust/examples/bench.rs +++ b/rust/examples/bench.rs @@ -11,13 +11,13 @@ use std::hint::black_box; use std::sync::{Arc, RwLock}; use std::time::{Duration, Instant}; -fn bench(name: &str, mut f: impl FnMut(u64)) { - f(0); +fn bench(name: &str, mut f: impl FnMut(u64) -> R) { + black_box(f(0)); let budget = Duration::from_secs(2); let start = Instant::now(); let mut n = 0u64; while start.elapsed() < budget { - f(n); + black_box(f(n)); n += 1; } let per = start.elapsed() / n as u32; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d084006..2a8cf38 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,5 +1,6 @@ //! mapsize: interactive terminal disk usage analyser (Rust port). +pub mod app; pub mod brand; pub mod cancel; pub mod config; diff --git a/rust/src/tui/infoview.rs b/rust/src/tui/infoview.rs index 14c1d11..6a5a858 100644 --- a/rust/src/tui/infoview.rs +++ b/rust/src/tui/infoview.rs @@ -3,7 +3,7 @@ use super::canvas::{Canvas, Style, BOLD}; use super::model::{Cmd, Model}; use super::table::{col, Table, TableRow}; -use super::{san, si_units}; +use super::san; use crate::inventory::{ErrKind, Tree, FLAG_ALLOC_UNKNOWN}; use crate::textutil; use crate::treemap::Rect; @@ -107,7 +107,7 @@ impl InfoView { line(cv, &mut y, "One filesystem", &st.one_file_system.to_string(), value); line(cv, &mut y, "Follow symlinks", &textutil::sanitize(&st.follow), value); line(cv, &mut y, "Size mode", m.size_mode.name(), value); - line(cv, &mut y, "Units", if si_units() { "SI (1000)" } else { "IEC (1024)" }, value); + line(cv, &mut y, "Units", if crate::textutil::si() { "SI (1000)" } else { "IEC (1024)" }, value); if root.has(FLAG_ALLOC_UNKNOWN) { line(cv, &mut y, "Note", "allocated size unavailable on this platform", Style::new(t.warn, t.bg)); } diff --git a/rust/src/tui/mod.rs b/rust/src/tui/mod.rs index 0703e7f..f923945 100644 --- a/rust/src/tui/mod.rs +++ b/rust/src/tui/mod.rs @@ -55,11 +55,6 @@ pub(crate) fn san(b: &[u8]) -> String { textutil::sanitize_bytes(b) } -/// Whether decimal (SI) units are selected. textutil keeps the switch -/// private, so it is inferred from the formatting. -pub(crate) fn si_units() -> bool { - textutil::size(1000).ends_with("kB") -} fn local_tm(unix_nanos: i64) -> libc::tm { let secs = unix_nanos.div_euclid(1_000_000_000) as libc::time_t; diff --git a/rust/src/tui/modals.rs b/rust/src/tui/modals.rs index 22c7a25..48de42b 100644 --- a/rust/src/tui/modals.rs +++ b/rust/src/tui/modals.rs @@ -7,7 +7,7 @@ use super::mapview::Group; use super::modal::{kv, styled, txt, wrap, Line, Modal, Span}; use super::model::{Cmd, Model}; use super::search::LineEditor; -use super::{fmt_time, pad_left, pad_right, san, si_units, trunc, tw}; +use super::{fmt_time, pad_left, pad_right, san, trunc, tw}; use crate::export; use crate::filter; use crate::inventory::{NodeId, Tree, FLAG_ALLOC_UNKNOWN, FLAG_HARDLINK_DUP, FLAG_INCOMPLETE, FLAG_LOOP, FLAG_SCANNED, FLAG_SKIPPED_FS, FLAG_SPARSE, FLAG_VIRTUAL_FS, NO_NODE}; @@ -321,7 +321,7 @@ impl Modal for HelpModal { row(&mut out, "Ctrl+C", "cancel scan; press again to quit"); row(&mut out, "q", "quit"); out.push(txt("")); - let units = if si_units() { "SI (kB = 1000 bytes)" } else { "IEC (KiB = 1024 bytes)" }; + let units = if crate::textutil::si() { "SI (kB = 1000 bytes)" } else { "IEC (KiB = 1024 bytes)" }; out.push(styled(format!("Sizes: {} ยท units: {units}", m.size_mode.name()), muted)); out }