Replace lazy_static with once_cell

This commit is contained in:
Alex Orlenko 2021-04-11 15:23:43 +01:00
parent c7541ef7d3
commit c19f12898d
2 changed files with 6 additions and 4 deletions

View file

@ -42,7 +42,7 @@ serialize = ["serde", "erased-serde"]
[dependencies]
mlua_derive = { version = "0.5", optional = true, path = "mlua_derive" }
bstr = { version = "0.2", features = ["std"], default_features = false }
lazy_static = { version = "1.4" }
once_cell = { version = "1.7" }
num-traits = { version = "0.2.14" }
futures-core = { version = "0.3.5", optional = true }
futures-task = { version = "0.3.5", optional = true }

View file

@ -6,13 +6,15 @@ use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
use std::sync::{Arc, Mutex};
use std::{mem, ptr, slice};
use once_cell::sync::Lazy;
use crate::error::{Error, Result};
use crate::ffi;
lazy_static::lazy_static! {
static METATABLE_CACHE: Lazy<Mutex<HashMap<TypeId, u8>>> = Lazy::new(|| {
// The capacity must(!) be greater than number of stored keys
static ref METATABLE_CACHE: Mutex<HashMap<TypeId, u8>> = Mutex::new(HashMap::with_capacity(32));
}
Mutex::new(HashMap::with_capacity(32))
});
// Checks that Lua has enough free stack space for future stack operations. On failure, this will
// panic with an internal error message.