Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/revlog/manifest.rs @ 52033:0ea323b7e3b1
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.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 30 Sep 2024 12:08:49 +0200 |
parents | db7dbe6f7bb2 |
children | 78fc666a3e94 |
line wrap: on
line diff
--- 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")), } }