File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,10 @@ impl easy::Handle {
74
74
self . bufs . borrow_mut ( ) . pop ( ) . unwrap_or_default ( )
75
75
}
76
76
77
+ /// This method is commonly called from the destructor of objects that previously claimed an entry
78
+ /// in the free-list with `free_buf()`.
79
+ /// They are welcome to take out the data themselves, for instance when the object is detached, to avoid
80
+ /// it to be reclaimed.
77
81
#[ inline]
78
82
pub ( crate ) fn reuse_buffer ( & self , data : & mut Vec < u8 > ) {
79
83
if data. capacity ( ) > 0 {
Original file line number Diff line number Diff line change @@ -29,16 +29,13 @@ impl AsRef<[u8]> for DetachedObject {
29
29
impl < ' repo > TryFrom < Object < ' repo > > for Commit < ' repo > {
30
30
type Error = Object < ' repo > ;
31
31
32
- fn try_from ( value : Object < ' repo > ) -> Result < Self , Self :: Error > {
32
+ fn try_from ( mut value : Object < ' repo > ) -> Result < Self , Self :: Error > {
33
33
let handle = value. handle ;
34
34
match value. kind {
35
35
object:: Kind :: Commit => Ok ( Commit {
36
36
id : value. id ,
37
37
handle,
38
- data : {
39
- drop ( value) ;
40
- handle. free_buf ( )
41
- } ,
38
+ data : steal ( & mut value. data ) ,
42
39
} ) ,
43
40
_ => Err ( value) ,
44
41
}
@@ -48,18 +45,21 @@ impl<'repo> TryFrom<Object<'repo>> for Commit<'repo> {
48
45
impl < ' repo > TryFrom < Object < ' repo > > for Tree < ' repo > {
49
46
type Error = Object < ' repo > ;
50
47
51
- fn try_from ( value : Object < ' repo > ) -> Result < Self , Self :: Error > {
48
+ fn try_from ( mut value : Object < ' repo > ) -> Result < Self , Self :: Error > {
52
49
let handle = value. handle ;
53
50
match value. kind {
54
51
object:: Kind :: Tree => Ok ( Tree {
55
52
id : value. id ,
56
53
handle,
57
- data : {
58
- drop ( value) ;
59
- handle. free_buf ( )
60
- } ,
54
+ data : steal ( & mut value. data ) ,
61
55
} ) ,
62
56
_ => Err ( value) ,
63
57
}
64
58
}
65
59
}
60
+
61
+ /// In conjunction with the handles free list, leaving an empty Vec in place of the original causes it to not be
62
+ /// returned to the free list.
63
+ fn steal ( data : & mut Vec < u8 > ) -> Vec < u8 > {
64
+ std:: mem:: take ( data)
65
+ }
You can’t perform that action at this time.
0 commit comments