Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lazy_static & once_cell with std::sync::OnceLock #376

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions src/buffer_pool/enabled.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#![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<Arc<BufferPool>> = Lazy::new(Default::default);

#[inline(always)]
pub fn get_buffer() -> Buffer {
BUFFER_POOL.get()
static BUFFER_POOL: OnceLock<Arc<BufferPool>> = OnceLock::new();
BUFFER_POOL.get_or_init(Default::default).get()
}

#[derive(Debug)]
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,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)]
Expand All @@ -1070,8 +1068,9 @@ mod test_misc {
_dummy(crate::error::Error::FromValueError(crate::Value::NULL));
}

lazy_static! {
pub static ref DATABASE_URL: String = def_database_url!();
#[allow(dead_code)]
fn database_url() {
def_database_url!();
}

def_get_opts!();
Expand Down
Loading