Skip to content

Commit 66b4a86

Browse files
committed
Remove MultiValue pool
1 parent 2114910 commit 66b4a86

2 files changed

Lines changed: 6 additions & 42 deletions

File tree

src/multi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<E: IntoLua> IntoLuaMulti for StdResult<(), E> {
3232
#[inline]
3333
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue> {
3434
match self {
35-
Ok(_) => Ok(MultiValue::new()),
35+
Ok(_) => const { Ok(MultiValue::new()) },
3636
Err(err) => (Nil, err).into_lua_multi(lua),
3737
}
3838
}
@@ -197,7 +197,7 @@ macro_rules! impl_tuple {
197197
impl IntoLuaMulti for () {
198198
#[inline]
199199
fn into_lua_multi(self, _: &Lua) -> Result<MultiValue> {
200-
Ok(MultiValue::new())
200+
const { Ok(MultiValue::new()) }
201201
}
202202

203203
#[inline]

src/value.rs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -745,35 +745,10 @@ pub trait FromLua: Sized {
745745
}
746746
}
747747

748-
// Per-thread size of the VecDeque pool for MultiValue container.
749-
const MULTIVALUE_POOL_SIZE: usize = 32;
750-
751-
thread_local! {
752-
static MULTIVALUE_POOL: RefCell<Vec<VecDeque<Value>>> = const { RefCell::new(Vec::new()) };
753-
}
754-
755748
/// Multiple Lua values used for both argument passing and also for multiple return values.
756-
#[derive(Debug, Clone)]
749+
#[derive(Default, Debug, Clone)]
757750
pub struct MultiValue(VecDeque<Value>);
758751

759-
impl Drop for MultiValue {
760-
fn drop(&mut self) {
761-
MULTIVALUE_POOL.with_borrow_mut(|pool| {
762-
if pool.len() < MULTIVALUE_POOL_SIZE {
763-
self.0.clear();
764-
pool.push(mem::take(&mut self.0));
765-
}
766-
});
767-
}
768-
}
769-
770-
impl Default for MultiValue {
771-
#[inline]
772-
fn default() -> MultiValue {
773-
MultiValue::new()
774-
}
775-
}
776-
777752
impl Deref for MultiValue {
778753
type Target = VecDeque<Value>;
779754

@@ -793,24 +768,13 @@ impl DerefMut for MultiValue {
793768
impl MultiValue {
794769
/// Creates an empty `MultiValue` containing no values.
795770
#[inline]
796-
pub fn new() -> MultiValue {
797-
Self::with_capacity(0)
771+
pub const fn new() -> MultiValue {
772+
MultiValue(VecDeque::new())
798773
}
799774

800775
/// Creates an empty `MultiValue` container with space for at least `capacity` elements.
801776
pub fn with_capacity(capacity: usize) -> MultiValue {
802-
let deque = MULTIVALUE_POOL.with_borrow_mut(|pool| {
803-
pool.pop().map_or_else(
804-
|| VecDeque::with_capacity(capacity),
805-
|mut deque| {
806-
if capacity > 0 {
807-
deque.reserve(capacity);
808-
}
809-
deque
810-
},
811-
)
812-
});
813-
MultiValue(deque)
777+
MultiValue(VecDeque::with_capacity(capacity))
814778
}
815779

816780
#[inline]

0 commit comments

Comments
 (0)