Show More
@@ -593,7 +593,9 b" impl Writer<'_, '_> {" | |||||
593 | // Reuse already-written nodes if possible |
|
593 | // Reuse already-written nodes if possible | |
594 | if self.append { |
|
594 | if self.append { | |
595 | if let dirstate_map::ChildNodesRef::OnDisk(nodes_slice) = nodes { |
|
595 | if let dirstate_map::ChildNodesRef::OnDisk(nodes_slice) = nodes { | |
596 |
let start = self.offset_of(nodes_slice) |
|
596 | let start = self.on_disk_offset_of(nodes_slice).expect( | |
|
597 | "dirstate-v2 OnDisk nodes not found within on_disk", | |||
|
598 | ); | |||
597 | let len = child_nodes_len_from_usize(nodes_slice.len()); |
|
599 | let len = child_nodes_len_from_usize(nodes_slice.len()); | |
598 | return Ok(ChildNodes { start, len }); |
|
600 | return Ok(ChildNodes { start, len }); | |
599 | } |
|
601 | } | |
@@ -679,11 +681,9 b" impl Writer<'_, '_> {" | |||||
679 | Ok(ChildNodes { start, len }) |
|
681 | Ok(ChildNodes { start, len }) | |
680 | } |
|
682 | } | |
681 |
|
683 | |||
682 |
/// |
|
684 | /// If the given slice of items is within `on_disk`, returns its offset | |
683 | /// start of `on_disk`. |
|
685 | /// from the start of `on_disk`. | |
684 | /// |
|
686 | fn on_disk_offset_of<T>(&self, slice: &[T]) -> Option<Offset> | |
685 | /// Panics if the given slice is not within `on_disk`. |
|
|||
686 | fn offset_of<T>(&self, slice: &[T]) -> Offset |
|
|||
687 | where |
|
687 | where | |
688 | T: BytesCast, |
|
688 | T: BytesCast, | |
689 | { |
|
689 | { | |
@@ -694,10 +694,14 b" impl Writer<'_, '_> {" | |||||
694 | } |
|
694 | } | |
695 | let slice_addresses = address_range(slice.as_bytes()); |
|
695 | let slice_addresses = address_range(slice.as_bytes()); | |
696 | let on_disk_addresses = address_range(self.dirstate_map.on_disk); |
|
696 | let on_disk_addresses = address_range(self.dirstate_map.on_disk); | |
697 |
|
|
697 | if on_disk_addresses.contains(slice_addresses.start()) | |
698 |
|
|
698 | && on_disk_addresses.contains(slice_addresses.end()) | |
699 | let offset = slice_addresses.start() - on_disk_addresses.start(); |
|
699 | { | |
700 | offset_from_usize(offset) |
|
700 | let offset = slice_addresses.start() - on_disk_addresses.start(); | |
|
701 | Some(offset_from_usize(offset)) | |||
|
702 | } else { | |||
|
703 | None | |||
|
704 | } | |||
701 | } |
|
705 | } | |
702 |
|
706 | |||
703 | fn current_offset(&mut self) -> Offset { |
|
707 | fn current_offset(&mut self) -> Offset { | |
@@ -709,8 +713,14 b" impl Writer<'_, '_> {" | |||||
709 | } |
|
713 | } | |
710 |
|
714 | |||
711 | fn write_path(&mut self, slice: &[u8]) -> PathSlice { |
|
715 | fn write_path(&mut self, slice: &[u8]) -> PathSlice { | |
|
716 | let len = path_len_from_usize(slice.len()); | |||
|
717 | // Reuse an already-written path if possible | |||
|
718 | if self.append { | |||
|
719 | if let Some(start) = self.on_disk_offset_of(slice) { | |||
|
720 | return PathSlice { start, len }; | |||
|
721 | } | |||
|
722 | } | |||
712 | let start = self.current_offset(); |
|
723 | let start = self.current_offset(); | |
713 | let len = path_len_from_usize(slice.len()); |
|
|||
714 | self.out.extend(slice.as_bytes()); |
|
724 | self.out.extend(slice.as_bytes()); | |
715 | PathSlice { start, len } |
|
725 | PathSlice { start, len } | |
716 | } |
|
726 | } |
General Comments 0
You need to be logged in to leave comments.
Login now