Rewrite mapsize in Rust and remove the Go implementation #1

Merged
andydixon merged 13 commits from rust-port into master 2026-10-08 19:33:31 +02:00
5 changed files with 8 additions and 12 deletions
Showing only changes of commit aa738cc8a1 - Show all commits
+3 -3
View File
@@ -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<R>(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;
+1
View File
@@ -1,5 +1,6 @@
//! mapsize: interactive terminal disk usage analyser (Rust port).
pub mod app;
pub mod brand;
pub mod cancel;
pub mod config;
+2 -2
View File
@@ -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));
}
-5
View File
@@ -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;
+2 -2
View File
@@ -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
}