Fix erase
This commit is contained in:
parent
d04c634d48
commit
4abd32d2c6
|
@ -159,21 +159,17 @@ impl ByteBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn erase(&mut self) -> Result<(), &'static str> {
|
pub fn erase(&mut self) -> Result<(), &'static str> {
|
||||||
let cur_len = match self.mmap {
|
let len = self.len();
|
||||||
// Nothing to do here...
|
if len > 0 {
|
||||||
None => return Ok(()),
|
// The order is important.
|
||||||
Some(Mmap { len: cur_len, .. }) => cur_len,
|
//
|
||||||
};
|
// 1. First we clear, and thus drop, the current mmap if any.
|
||||||
|
// 2. And then we create a new one.
|
||||||
// The order is important.
|
//
|
||||||
//
|
// Otherwise we double the peak memory consumption.
|
||||||
// 1. First we clear, and thus drop, the current mmap if any.
|
self.mmap = None;
|
||||||
// 2. And then we create a new one.
|
self.mmap = Some(Mmap::new(len)?);
|
||||||
//
|
}
|
||||||
// Otherwise we double the peak memory consumption.
|
|
||||||
self.mmap = None;
|
|
||||||
self.mmap = Some(Mmap::new(cur_len)?);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue