From 1f278eb6e0c266ec9c4cb04bc883ebf3331465a1 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 3 Oct 2023 17:55:08 -0700 Subject: [PATCH] Second get method in Pool to get or allocate if larger is needed. --- src/buf.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/buf.rs b/src/buf.rs index 7a1be5a..24b4c59 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -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 {