Second get method in Pool to get or allocate if larger is needed.

This commit is contained in:
Adam Ierymenko
2023-10-03 17:55:08 -07:00
parent 336c7c9dd6
commit 1f278eb6e0
+10
View File
@@ -298,6 +298,16 @@ impl Pool {
}
}
}
/// Get a buffer from the pool or direct allocation if min_capacity is larger than pool buffer capacity.
#[inline]
pub fn get_with_min_capacity(&self, min_capacity: usize) -> Buf {
if unsafe { (*self.0).buf_capacity } >= min_capacity {
self.get()
} else {
Buf::new(min_capacity)
}
}
}
impl Drop for Pool {