Skip to content

Commit

Permalink
refactor: remove once_cell crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Nov 29, 2023
1 parent 8520b95 commit 0f82409
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
dyn-clone = "1"
rustc-hash = "1"
once_cell = "1"
dashmap = "5"
substring = "1"
smallvec = "1.11.2"
Expand Down
7 changes: 3 additions & 4 deletions src/cached_source.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{
borrow::Cow,
hash::{BuildHasherDefault, Hash},
sync::Arc,
sync::{Arc, OnceLock},
};

use dashmap::DashMap;
use once_cell::sync::OnceCell;
use rustc_hash::FxHasher;

use crate::{helpers::StreamChunks, MapOptions, Source, SourceMap};
Expand Down Expand Up @@ -45,8 +44,8 @@ use crate::{helpers::StreamChunks, MapOptions, Source, SourceMap};
/// ```
pub struct CachedSource<T> {
inner: Arc<T>,
cached_buffer: OnceCell<Vec<u8>>,
cached_source: OnceCell<Arc<str>>,
cached_buffer: OnceLock<Vec<u8>>,
cached_source: OnceLock<Arc<str>>,
cached_maps:
DashMap<MapOptions, Option<SourceMap>, BuildHasherDefault<FxHasher>>,
}
Expand Down
13 changes: 7 additions & 6 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use rustc_hash::FxHashMap as HashMap;
use std::{
borrow::{BorrowMut, Cow},
cell::RefCell,
cell::{OnceCell, RefCell},
rc::Rc,
sync::Arc,
};

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

pub fn get_map<S: StreamChunks>(
stream: &S,
Expand Down Expand Up @@ -925,14 +926,14 @@ struct SourceMapLineData {
#[derive(Debug)]
struct SourceMapLineChunk {
content: ArcStr,
cached: once_cell::sync::OnceCell<WithIndices<ArcStr>>,
cached: OnceCell<WithIndices<ArcStr>>,
}

impl SourceMapLineChunk {
pub fn new(content: ArcStr) -> Self {
Self {
content,
cached: once_cell::sync::OnceCell::new(),
cached: OnceCell::new(),
}
}

Expand Down Expand Up @@ -1062,7 +1063,7 @@ pub fn stream_chunks_of_combined_source_map(
original_source_lines = if let Some(Some(original_source)) =
inner_source_contents.get(&inner_source_index)
{
Some(Arc::new(
Some(Rc::new(
split_into_lines(original_source)
.into_iter()
.map(|s| WithIndices::new(s.into()))
Expand Down Expand Up @@ -1165,7 +1166,7 @@ pub fn stream_chunks_of_combined_source_map(
.and_then(|original_source| {
original_source.as_ref().map(|s| {
let lines = split_into_lines(s);
Arc::new(
Rc::new(
lines
.into_iter()
.map(|s| WithIndices::new(s.into()))
Expand Down
7 changes: 3 additions & 4 deletions src/replace_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::{
hash::{Hash, Hasher},
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex, MutexGuard,
Arc, Mutex, MutexGuard, OnceLock,
},
};

use once_cell::sync::OnceCell;
use rustc_hash::FxHashMap as HashMap;

use crate::{
Expand Down Expand Up @@ -38,7 +37,7 @@ use crate::{
/// ```
pub struct ReplaceSource<T> {
inner: Arc<T>,
inner_source_code: OnceCell<Box<str>>,
inner_source_code: OnceLock<Box<str>>,
replacements: Mutex<Vec<Replacement>>,
/// Whether `replacements` is sorted.
is_sorted: AtomicBool,
Expand Down Expand Up @@ -91,7 +90,7 @@ impl<T> ReplaceSource<T> {
pub fn new(source: T) -> Self {
Self {
inner: Arc::new(source),
inner_source_code: OnceCell::new(),
inner_source_code: OnceLock::new(),
replacements: Mutex::new(Vec::new()),
is_sorted: AtomicBool::new(true),
}
Expand Down
2 changes: 1 addition & 1 deletion src/with_indices.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use once_cell::sync::OnceCell;
use std::cell::OnceCell;

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

0 comments on commit 0f82409

Please sign in to comment.