Skip to content

Commit b285097

Browse files
committed
Add note on why we consume the tree for looking up an entry. (#470)
The disadvantage of doing that is that we copy the name, which allocates, instead of just returning it by reference.
1 parent 5ec714f commit b285097

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

git-repository/src/object/tree/iter.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct EntryRef<'repo, 'a> {
66
/// The actual entry ref we are wrapping.
77
pub inner: git_object::tree::EntryRef<'a>,
88

9-
repo: &'repo Repository,
9+
pub(crate) repo: &'repo Repository,
1010
}
1111

1212
impl<'repo, 'a> EntryRef<'repo, 'a> {
@@ -24,6 +24,11 @@ impl<'repo, 'a> EntryRef<'repo, 'a> {
2424
pub fn id(&self) -> crate::Id<'repo> {
2525
crate::Id::from_id(self.inner.oid, self.repo)
2626
}
27+
28+
/// Return the entries id, without repository connection.
29+
pub fn oid(&self) -> git_hash::ObjectId {
30+
self.inner.oid.to_owned()
31+
}
2732
}
2833

2934
impl<'repo, 'a> std::fmt::Display for EntryRef<'repo, 'a> {

git-repository/src/object/tree/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ impl<'repo> Tree<'repo> {
3131
/// Searching tree entries is currently done in sequence, which allows to the search to be allocation free. It would be possible
3232
/// to re-use a vector and use a binary search instead, which might be able to improve performance over all.
3333
/// However, a benchmark should be created first to have some data and see which trade-off to choose here.
34+
///
35+
/// # Why is this consunming?
36+
///
37+
/// The borrow checker shows pathological behaviour in loops that mutate a buffer, but also want to return from it.
38+
/// Workarounds include keeping an index and doing a separate access to the memory, which seems hard to do here without
39+
/// re-parsing the entries.
3440
pub fn lookup_entry<I, P>(mut self, path: I) -> Result<Option<git_object::tree::Entry>, find::existing::Error>
3541
where
3642
I: IntoIterator<Item = P>,

0 commit comments

Comments
 (0)