From 5346292f8ecd4d196cb74b8dc73cb6ee311ed6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Wed, 17 Apr 2024 22:05:25 +0000 Subject: [PATCH] Replace lazy_static & once_cell with std::sync::OnceLock --- Cargo.toml | 2 -- src/buffer_pool/enabled.rs | 8 +++----- src/lib.rs | 6 ++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8eacd68..cbd04d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,6 @@ frunk = ["mysql_common/frunk"] binlog = ["mysql_common/binlog"] [dev-dependencies] -lazy_static = "1.4.0" rand = "0.8.2" serde_derive = "1" time = "0.3" @@ -90,7 +89,6 @@ flate2 = { version = "1.0", default-features = false } lru = "0.12" mysql_common = { version = "0.32", default-features = false } socket2 = "0.5.2" -once_cell = "1.7.2" pem = "3" percent-encoding = "2.1.0" serde = "1" diff --git a/src/buffer_pool/enabled.rs b/src/buffer_pool/enabled.rs index d2af5fd..d95bfc9 100644 --- a/src/buffer_pool/enabled.rs +++ b/src/buffer_pool/enabled.rs @@ -1,18 +1,16 @@ #![cfg(feature = "buffer-pool")] use crossbeam::queue::ArrayQueue; -use once_cell::sync::Lazy; -use std::{mem::take, ops::Deref, sync::Arc}; +use std::{mem::take, ops::Deref, sync::{Arc, OnceLock}}; const DEFAULT_MYSQL_BUFFER_POOL_CAP: usize = 128; const DEFAULT_MYSQL_BUFFER_SIZE_CAP: usize = 4 * 1024 * 1024; -static BUFFER_POOL: Lazy> = Lazy::new(Default::default); - #[inline(always)] pub fn get_buffer() -> Buffer { - BUFFER_POOL.get() + static BUFFER_POOL: OnceLock> = OnceLock::new(); + BUFFER_POOL.get_or_init(Default::default).get() } #[derive(Debug)] diff --git a/src/lib.rs b/src/lib.rs index 068e60b..2ba0222 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1059,8 +1059,6 @@ macro_rules! doctest_wrapper { #[cfg(test)] mod test_misc { - use lazy_static::lazy_static; - use crate::{def_database_url, def_get_opts}; #[allow(dead_code)] @@ -1069,8 +1067,8 @@ mod test_misc { _dummy(crate::error::Error::FromValueError(crate::Value::NULL)); } - lazy_static! { - pub static ref DATABASE_URL: String = def_database_url!(); + fn database_url() { + def_database_url!(); } def_get_opts!();