Skip to content

Commit 426e48a

Browse files
committed
refactor: remove once_cell crate
1 parent 438d444 commit 426e48a

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ serde = { version = "1", features = ["derive"] }
3333
serde_json = "1"
3434
dyn-clone = "1"
3535
rustc-hash = "1"
36-
once_cell = "1"
3736
dashmap = "5"
3837
substring = "1"
3938
smallvec = "1.11.2"

src/cached_source.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::{
22
borrow::Cow,
33
hash::{BuildHasherDefault, Hash},
4-
sync::Arc,
4+
sync::{Arc, OnceLock},
55
};
66

77
use dashmap::DashMap;
8-
use once_cell::sync::OnceCell;
98
use rustc_hash::FxHasher;
109

1110
use crate::{helpers::StreamChunks, MapOptions, Source, SourceMap};
@@ -45,8 +44,8 @@ use crate::{helpers::StreamChunks, MapOptions, Source, SourceMap};
4544
/// ```
4645
pub struct CachedSource<T> {
4746
inner: Arc<T>,
48-
cached_buffer: OnceCell<Vec<u8>>,
49-
cached_source: OnceCell<Arc<str>>,
47+
cached_buffer: OnceLock<Vec<u8>>,
48+
cached_source: OnceLock<Arc<str>>,
5049
cached_maps:
5150
DashMap<MapOptions, Option<SourceMap>, BuildHasherDefault<FxHasher>>,
5251
}

src/helpers.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use rustc_hash::FxHashMap as HashMap;
22
use std::{
33
borrow::{BorrowMut, Cow},
4-
cell::RefCell,
4+
cell::{OnceCell, RefCell},
5+
rc::Rc,
56
sync::Arc,
67
};
78

@@ -15,7 +16,7 @@ use crate::{
1516
type ArcStr = Arc<str>;
1617
// Adding this type because sourceContentLine not happy
1718
type InnerSourceContentLine =
18-
RefCell<HashMap<i64, Option<Arc<Vec<WithIndices<ArcStr>>>>>>;
19+
RefCell<HashMap<i64, Option<Rc<Vec<WithIndices<ArcStr>>>>>>;
1920

2021
pub fn get_map<S: StreamChunks>(
2122
stream: &S,
@@ -925,14 +926,14 @@ struct SourceMapLineData {
925926
#[derive(Debug)]
926927
struct SourceMapLineChunk {
927928
content: ArcStr,
928-
cached: once_cell::sync::OnceCell<WithIndices<ArcStr>>,
929+
cached: OnceCell<WithIndices<ArcStr>>,
929930
}
930931

931932
impl SourceMapLineChunk {
932933
pub fn new(content: ArcStr) -> Self {
933934
Self {
934935
content,
935-
cached: once_cell::sync::OnceCell::new(),
936+
cached: OnceCell::new(),
936937
}
937938
}
938939

@@ -1062,7 +1063,7 @@ pub fn stream_chunks_of_combined_source_map(
10621063
original_source_lines = if let Some(Some(original_source)) =
10631064
inner_source_contents.get(&inner_source_index)
10641065
{
1065-
Some(Arc::new(
1066+
Some(Rc::new(
10661067
split_into_lines(original_source)
10671068
.into_iter()
10681069
.map(|s| WithIndices::new(s.into()))
@@ -1165,7 +1166,7 @@ pub fn stream_chunks_of_combined_source_map(
11651166
.and_then(|original_source| {
11661167
original_source.as_ref().map(|s| {
11671168
let lines = split_into_lines(s);
1168-
Arc::new(
1169+
Rc::new(
11691170
lines
11701171
.into_iter()
11711172
.map(|s| WithIndices::new(s.into()))

src/replace_source.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ use std::{
44
hash::{Hash, Hasher},
55
sync::{
66
atomic::{AtomicBool, Ordering},
7-
Arc, Mutex, MutexGuard,
7+
Arc, Mutex, MutexGuard, OnceLock,
88
},
99
};
1010

11-
use once_cell::sync::OnceCell;
1211
use rustc_hash::FxHashMap as HashMap;
1312

1413
use crate::{
@@ -38,7 +37,7 @@ use crate::{
3837
/// ```
3938
pub struct ReplaceSource<T> {
4039
inner: Arc<T>,
41-
inner_source_code: OnceCell<Box<str>>,
40+
inner_source_code: OnceLock<Box<str>>,
4241
replacements: Mutex<Vec<Replacement>>,
4342
/// Whether `replacements` is sorted.
4443
is_sorted: AtomicBool,
@@ -91,7 +90,7 @@ impl<T> ReplaceSource<T> {
9190
pub fn new(source: T) -> Self {
9291
Self {
9392
inner: Arc::new(source),
94-
inner_source_code: OnceCell::new(),
93+
inner_source_code: OnceLock::new(),
9594
replacements: Mutex::new(Vec::new()),
9695
is_sorted: AtomicBool::new(true),
9796
}

src/with_indices.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use once_cell::sync::OnceCell;
1+
use std::cell::OnceCell;
22

33
#[derive(Debug, Clone)]
44
pub struct WithIndices<T: AsRef<str>> {

0 commit comments

Comments
 (0)