Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/revlog/nodemap.rs @ 52778:198674d830d6
rust-nodemap: add a `Sync` bound to the buffer type
This has always been ok to be `Sync` in all of our contexts, we've just never
needed to make it explicit. Now that we're starting to do more things in
parallel, let's add the bound in a new type alias to avoid repetition.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Fri, 24 Jan 2025 12:04:37 -0500 |
parents | 532e74ad3ff6 |
children | 3ea5bd40b8dc |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/nodemap.rs Thu Jan 16 15:42:54 2025 -0500 +++ b/rust/hg-core/src/revlog/nodemap.rs Fri Jan 24 12:04:37 2025 -0500 @@ -25,6 +25,8 @@ use std::ops::Deref; use std::ops::Index; +type NodeTreeBuffer = Box<dyn Deref<Target = [u8]> + Send + Sync>; + #[derive(Debug, PartialEq)] pub enum NodeMapError { /// A `NodePrefix` matches several [`Revision`]s. @@ -224,7 +226,7 @@ /// The mutable root [`Block`] is kept apart so that we don't have to rebump /// it on each insertion. pub struct NodeTree { - readonly: Box<dyn Deref<Target = [Block]> + Send>, + readonly: Box<dyn Deref<Target = [Block]> + Send + Sync>, growable: Vec<Block>, root: Block, masked_inner_blocks: usize, @@ -299,7 +301,7 @@ /// Initiate a NodeTree from an immutable slice-like of `Block` /// /// We keep `readonly` and clone its root block if it isn't empty. - fn new(readonly: Box<dyn Deref<Target = [Block]> + Send>) -> Self { + fn new(readonly: Box<dyn Deref<Target = [Block]> + Send + Sync>) -> Self { let root = readonly.last().cloned().unwrap_or_else(Block::new); NodeTree { readonly, @@ -321,10 +323,7 @@ /// First use-case for this would be to support Mercurial shell hooks. /// /// panics if `buffer` is smaller than `amount` - pub fn load_bytes( - bytes: Box<dyn Deref<Target = [u8]> + Send>, - amount: usize, - ) -> Self { + pub fn load_bytes(bytes: NodeTreeBuffer, amount: usize) -> Self { NodeTree::new(Box::new(NodeTreeBytes::new(bytes, amount))) } @@ -562,15 +561,12 @@ } pub struct NodeTreeBytes { - buffer: Box<dyn Deref<Target = [u8]> + Send>, + buffer: NodeTreeBuffer, len_in_blocks: usize, } impl NodeTreeBytes { - fn new( - buffer: Box<dyn Deref<Target = [u8]> + Send>, - amount: usize, - ) -> Self { + fn new(buffer: NodeTreeBuffer, amount: usize) -> Self { assert!(buffer.len() >= amount); let len_in_blocks = amount / size_of::<Block>(); NodeTreeBytes {