rust-manifest: encode flags as `Option<NonZeroU8>`
This makes the compiler use the niche optimization for all flags: since 0 is
not a valid representation of any flags, we can use 0 as a replacement for
`None`, which reduces memory footprint and could yield a little performance
improvement over many iterations.
--- a/rust/hg-core/src/revlog/manifest.rs Mon Sep 30 17:46:52 2024 +0200
+++ b/rust/hg-core/src/revlog/manifest.rs Mon Sep 30 12:08:49 2024 +0200
@@ -1,3 +1,5 @@
+use std::num::NonZeroU8;
+
use crate::errors::HgError;
use crate::revlog::{Node, NodePrefix};
use crate::revlog::{Revlog, RevlogError};
@@ -178,7 +180,7 @@
pub hex_node_id: &'manifest [u8],
/// `Some` values are b'x', b'l', or 't'
- pub flags: Option<u8>,
+ pub flags: Option<NonZeroU8>,
}
impl<'a> ManifestEntry<'a> {
@@ -198,7 +200,7 @@
Self {
path: HgPath::new(path),
hex_node_id,
- flags,
+ flags: flags.map(|f| f.try_into().expect("invalid flag")),
}
}
--- a/rust/rhg/src/commands/status.rs Mon Sep 30 17:46:52 2024 +0200
+++ b/rust/rhg/src/commands/status.rs Mon Sep 30 12:08:49 2024 +0200
@@ -776,13 +776,13 @@
let entry_flags = if check_exec {
entry.flags
- } else if entry.flags == Some(b'x') {
+ } else if entry.flags.map(|f| f.into()) == Some(b'x') {
None
} else {
entry.flags
};
- if entry_flags != fs_flags {
+ if entry_flags.map(|f| f.into()) != fs_flags {
return Ok(UnsureOutcome::Modified);
}
let filelog = hg::filelog::Filelog::open_vfs(