Skip to content

Commit d27857d

Browse files
committed
extract a ItemSliceSend::get_mut() from Node::into_child_iter()
1 parent d6b8977 commit d27857d

File tree

1 file changed

+13
-9
lines changed
  • gix-pack/src/cache/delta/traverse

1 file changed

+13
-9
lines changed

gix-pack/src/cache/delta/traverse/util.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ where
2020
phantom: PhantomData,
2121
}
2222
}
23+
24+
/// SAFETY: The index must point into the slice and must not be reused concurrently.
25+
#[allow(unsafe_code)]
26+
pub unsafe fn get_mut(&self, index: usize) -> &'a mut T {
27+
// SAFETY: The children array is alive by the 'a lifetime.
28+
unsafe { &mut *self.items.add(index) }
29+
}
2330
}
2431

2532
/// SAFETY: This would be unsafe if this would ever be abused, but it's used internally and only in a way that assure that the pointers
@@ -72,15 +79,12 @@ impl<'a, T: Send> Node<'a, T> {
7279
/// Children are `Node`s referring to pack entries whose base object is this pack entry.
7380
pub fn into_child_iter(self) -> impl Iterator<Item = Node<'a, T>> + 'a {
7481
let children = self.child_items;
75-
self.item.children.iter().map(move |&index| {
76-
// SAFETY: The children array is alive by the 'a lifetime.
77-
// SAFETY: The index is a valid index into the children array.
78-
// SAFETY: The resulting mutable pointer cannot be yielded by any other node.
79-
#[allow(unsafe_code)]
80-
Node {
81-
item: unsafe { &mut *children.items.add(index as usize) },
82-
child_items: children.clone(),
83-
}
82+
// SAFETY: The index is a valid index into the children array.
83+
// SAFETY: The resulting mutable pointer cannot be yielded by any other node.
84+
#[allow(unsafe_code)]
85+
self.item.children.iter().map(move |&index| Node {
86+
item: unsafe { children.get_mut(index as usize) },
87+
child_items: children.clone(),
8488
})
8589
}
8690
}

0 commit comments

Comments
 (0)