Skip to content

Commit 32f1c7d

Browse files
committed
Optimize Repository::write_object: Avoid dup momo
By splitting function into two halfs: First half uses `object: impl gix_object::WriteTo` and the second half uses no generic to avoid dup codegen. Signed-off-by: Jiahao XU <[email protected]>
1 parent cf70a2e commit 32f1c7d

13 files changed

+6
-2
lines changed

gix/src/repository/object.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,17 @@ impl crate::Repository {
116116
let mut buf = self.shared_empty_buf();
117117
object.write_to(buf.deref_mut()).expect("write to memory works");
118118

119-
let oid = gix_object::compute_hash(self.object_hash(), object.kind(), &buf);
119+
self.write_object_inner(&buf, object.kind())
120+
}
121+
122+
fn write_object_inner(&self, buf: &[u8], kind: gix_object::Kind) -> Result<Id<'_>, object::write::Error> {
123+
let oid = gix_object::compute_hash(self.object_hash(), kind, &buf);
120124
if self.objects.contains(&oid) {
121125
return Ok(oid.attach(self));
122126
}
123127

124128
self.objects
125-
.write_buf(object.kind(), &buf)
129+
.write_buf(kind, &buf)
126130
.map(|oid| oid.attach(self))
127131
.map_err(Into::into)
128132
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)