Skip to content

Commit 0fb4c91

Browse files
committed
handle won't try to reuse empty buffers to allow it to be claimed (#293)
When detaching an object, it's feasible to avoid cloning as it might be the last buffer the user needs. Now that's possble by not reclaiming the empty vec these users would leave in the original buffers place when the object is dropped.
1 parent 7d1aba1 commit 0fb4c91

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

git-repository/examples/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use git_odb::FindExt;
44
use git_repository as git;
55

66
fn main() -> Result<(), Box<dyn std::error::Error>> {
7-
let repo = git_repository::discover(".")?;
7+
let repo = git::discover(".")?;
88
println!(
99
"Repo: {}",
1010
repo.work_tree.as_deref().unwrap_or(repo.git_dir()).display()

git-repository/src/easy/handle.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ impl easy::Handle {
7676

7777
#[inline]
7878
pub(crate) fn reuse_buffer(&self, data: &mut Vec<u8>) {
79-
self.bufs.borrow_mut().push(std::mem::take(data));
79+
if data.capacity() > 0 {
80+
self.bufs.borrow_mut().push(std::mem::take(data));
81+
}
8082
}
8183
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ impl<'repo> Object<'repo> {
8181
}
8282

8383
/// Turn this instance into an owned one, copying our data in the process.
84-
pub fn into_owned(self) -> DetachedObject {
84+
pub fn into_owned(mut self) -> DetachedObject {
8585
DetachedObject {
8686
id: self.id,
8787
kind: self.kind,
88-
data: self.data.clone(),
88+
data: std::mem::take(&mut self.data),
8989
}
9090
}
9191

0 commit comments

Comments
 (0)