Mercurial > hg
comparison rust/hg-core/src/dirstate_tree/on_disk.rs @ 47331:0252600fd1cf
dirstate-tree: Downgrade `&mut Node` to `&Node` in status and serialization
Mutable access is not used, and upcoming changes will make it more costly
(with copy-on-write nodes that can be read from disk representation)
Differential Revision: https://phab.mercurial-scm.org/D10745
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 19 May 2021 13:15:00 +0200 |
parents | 73f23e7610f8 |
children | 69530e5d4fe5 |
comparison
equal
deleted
inserted
replaced
47330:73f23e7610f8 | 47331:0252600fd1cf |
---|---|
256 out[..header_len].copy_from_slice(header.as_bytes()); | 256 out[..header_len].copy_from_slice(header.as_bytes()); |
257 Ok(out) | 257 Ok(out) |
258 } | 258 } |
259 | 259 |
260 fn write_nodes( | 260 fn write_nodes( |
261 nodes: &mut dirstate_map::ChildNodes, | 261 nodes: &dirstate_map::ChildNodes, |
262 out: &mut Vec<u8>, | 262 out: &mut Vec<u8>, |
263 ) -> Result<ChildNodes, DirstateError> { | 263 ) -> Result<ChildNodes, DirstateError> { |
264 // `dirstate_map::ChildNodes` is a `HashMap` with undefined iteration | 264 // `dirstate_map::ChildNodes` is a `HashMap` with undefined iteration |
265 // order. Sort to enable binary search in the written file. | 265 // order. Sort to enable binary search in the written file. |
266 let nodes = dirstate_map::Node::sorted(nodes); | 266 let nodes = dirstate_map::Node::sorted(nodes); |
267 | 267 |
268 // First accumulate serialized nodes in a `Vec` | 268 // First accumulate serialized nodes in a `Vec` |
269 let mut on_disk_nodes = Vec::with_capacity(nodes.len()); | 269 let mut on_disk_nodes = Vec::with_capacity(nodes.len()); |
270 for (full_path, node) in nodes { | 270 for (full_path, node) in nodes { |
271 on_disk_nodes.push(Node { | 271 on_disk_nodes.push(Node { |
272 children: write_nodes(&mut node.children, out)?, | 272 children: write_nodes(&node.children, out)?, |
273 tracked_descendants_count: node.tracked_descendants_count.into(), | 273 tracked_descendants_count: node.tracked_descendants_count.into(), |
274 full_path: write_slice::<u8>( | 274 full_path: write_slice::<u8>( |
275 full_path.full_path().as_bytes(), | 275 full_path.full_path().as_bytes(), |
276 out, | 276 out, |
277 ), | 277 ), |
285 Slice { | 285 Slice { |
286 start: 0.into(), | 286 start: 0.into(), |
287 len: 0.into(), | 287 len: 0.into(), |
288 } | 288 } |
289 }, | 289 }, |
290 entry: if let Some(entry) = &mut node.entry { | 290 entry: if let Some(entry) = &node.entry { |
291 OptEntry { | 291 OptEntry { |
292 state: entry.state.into(), | 292 state: entry.state.into(), |
293 mode: entry.mode.into(), | 293 mode: entry.mode.into(), |
294 mtime: entry.mtime.into(), | 294 mtime: entry.mtime.into(), |
295 size: entry.size.into(), | 295 size: entry.size.into(), |