Skip to content

Commit

Permalink
Replace lazy_static & once_cell with std::sync::OnceLock
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex authored and blackbeam committed May 20, 2024
1 parent 6156511 commit e37d048
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
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

0 comments on commit e37d048

Please sign in to comment.