Skip to content

Commit ca8a373

Browse files
committed
Optimize Repository::write_blob_stream: Avoid dup codegen
Signed-off-by: Jiahao XU <[email protected]>
1 parent bae928d commit ca8a373

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gix/src/repository/object.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,18 @@ impl crate::Repository {
160160
) -> Result<Id<'_>, object::write::Error> {
161161
let mut buf = self.shared_empty_buf();
162162
std::io::copy(&mut bytes, buf.deref_mut()).expect("write to memory works");
163-
let oid = gix_object::compute_hash(self.object_hash(), gix_object::Kind::Blob, &buf);
163+
164+
self.write_blob_stream_inner(&buf)
165+
}
166+
167+
fn write_blob_stream_inner(&self, buf: &[u8]) -> Result<Id<'_>, object::write::Error> {
168+
let oid = gix_object::compute_hash(self.object_hash(), gix_object::Kind::Blob, buf);
164169
if self.objects.contains(&oid) {
165170
return Ok(oid.attach(self));
166171
}
167172

168173
self.objects
169-
.write_buf(gix_object::Kind::Blob, &buf)
174+
.write_buf(gix_object::Kind::Blob, buf)
170175
.map_err(Into::into)
171176
.map(|oid| oid.attach(self))
172177
}

0 commit comments

Comments
 (0)