Skip to content

Commit e03f290

Browse files
MSRV 1.70 + Replace once_cell::sync::Lazy with std::sync::OnceLock (#287)
* Update MSRV to 1.70 * Replace `once_cell::sync::Lazy` with `std::sync::OnceLock`
1 parent 471ca0d commit e03f290

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
strategy:
2222
matrix:
23-
rust: [1.61.0, nightly, beta, stable]
23+
rust: [1.70.0, nightly, beta, stable]
2424

2525
steps:
2626
- uses: actions/checkout@v2

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ default = ["serde_support"]
2323

2424
[dependencies]
2525
precomputed-hash = "0.1"
26-
once_cell = "1.10.0"
2726
serde = { version = "1", optional = true }
2827
phf_shared = "0.11"
2928
new_debug_unreachable = "1.0.2"

src/atom.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use crate::dynamic_set::{Entry, DYNAMIC_SET};
10+
use crate::dynamic_set::{dynamic_set, Entry};
1111
use crate::static_sets::StaticAtomSet;
1212
use debug_unreachable::debug_unreachable;
1313

@@ -221,7 +221,7 @@ impl<'a, Static: StaticAtomSet> From<Cow<'a, str>> for Atom<Static> {
221221
}
222222
} else {
223223
Self::try_static_internal(&*string_to_add).unwrap_or_else(|hash| {
224-
let ptr: std::ptr::NonNull<Entry> = DYNAMIC_SET.insert(string_to_add, hash.g);
224+
let ptr: std::ptr::NonNull<Entry> = dynamic_set().insert(string_to_add, hash.g);
225225
let data = ptr.as_ptr() as u64;
226226
debug_assert!(0 == data & TAG_MASK);
227227
Atom {
@@ -257,7 +257,7 @@ impl<Static> Drop for Atom<Static> {
257257

258258
// Out of line to guide inlining.
259259
fn drop_slow<Static>(this: &mut Atom<Static>) {
260-
DYNAMIC_SET.remove(this.unsafe_data.get() as *mut Entry);
260+
dynamic_set().remove(this.unsafe_data.get() as *mut Entry);
261261
}
262262
}
263263
}

src/dynamic_set.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use once_cell::sync::Lazy;
1110
use parking_lot::Mutex;
1211
use std::borrow::Cow;
1312
use std::mem;
1413
use std::ptr::NonNull;
1514
use std::sync::atomic::AtomicIsize;
1615
use std::sync::atomic::Ordering::SeqCst;
16+
use std::sync::OnceLock;
1717

1818
const NB_BUCKETS: usize = 1 << 12; // 4096
1919
const BUCKET_MASK: u32 = (1 << 12) - 1;
@@ -38,16 +38,20 @@ fn entry_alignment_is_sufficient() {
3838
assert!(mem::align_of::<Entry>() >= ENTRY_ALIGNMENT);
3939
}
4040

41-
pub(crate) static DYNAMIC_SET: Lazy<Set> = Lazy::new(|| {
41+
pub(crate) fn dynamic_set() -> &'static Set {
4242
// NOTE: Using const initialization for buckets breaks the small-stack test.
4343
// ```
4444
// // buckets: [Mutex<Option<Box<Entry>>>; NB_BUCKETS],
4545
// const MUTEX: Mutex<Option<Box<Entry>>> = Mutex::new(None);
4646
// let buckets = Box::new([MUTEX; NB_BUCKETS]);
4747
// ```
48-
let buckets = (0..NB_BUCKETS).map(|_| Mutex::new(None)).collect();
49-
Set { buckets }
50-
});
48+
static DYNAMIC_SET: OnceLock<Set> = OnceLock::new();
49+
50+
DYNAMIC_SET.get_or_init(|| {
51+
let buckets = (0..NB_BUCKETS).map(|_| Mutex::new(None)).collect();
52+
Set { buckets }
53+
})
54+
}
5155

5256
impl Set {
5357
pub(crate) fn insert(&self, string: Cow<str>, hash: u32) -> NonNull<Entry> {

0 commit comments

Comments
 (0)