Skip to content

Commit f73e8c7

Browse files
committed
perf: rm SourceMapLineChunk
1 parent 585bede commit f73e8c7

File tree

2 files changed

+5
-33
lines changed

2 files changed

+5
-33
lines changed

src/helpers.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use arrayvec::ArrayVec;
22
use rustc_hash::FxHashMap as HashMap;
33
use std::{
44
borrow::{BorrowMut, Cow},
5-
cell::{OnceCell, RefCell},
5+
cell::RefCell,
66
rc::Rc,
77
};
88

@@ -750,29 +750,7 @@ fn stream_chunks_of_source_map_lines_full<'a>(
750750
#[derive(Debug)]
751751
struct SourceMapLineData<'a> {
752752
pub mappings_data: Vec<i64>,
753-
pub chunks: Vec<SourceMapLineChunk<'a>>,
754-
}
755-
756-
#[derive(Debug)]
757-
struct SourceMapLineChunk<'a> {
758-
content: Cow<'a, str>,
759-
cached: OnceCell<WithIndices<Cow<'a, str>>>,
760-
}
761-
762-
impl<'a> SourceMapLineChunk<'a> {
763-
pub fn new(content: Cow<'a, str>) -> Self {
764-
Self {
765-
content,
766-
cached: OnceCell::new(),
767-
}
768-
}
769-
770-
pub fn substring(&self, start_index: usize, end_index: usize) -> &str {
771-
let cached = self
772-
.cached
773-
.get_or_init(|| WithIndices::new(self.content.clone()));
774-
cached.substring(start_index, end_index)
775-
}
753+
pub chunks: Vec<WithIndices<Cow<'a, str>>>,
776754
}
777755

778756
type InnerSourceIndexValueMapping<'a> =
@@ -1206,7 +1184,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
12061184
.unwrap_or(-1),
12071185
);
12081186
// SAFETY: final_source is false
1209-
let chunk = SourceMapLineChunk::new(chunk.unwrap());
1187+
let chunk = WithIndices::new(chunk.unwrap());
12101188
data.chunks.push(chunk);
12111189
},
12121190
&mut |i, source, source_content| {

src/replace_source.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,7 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
412412
original_line: original.original_line,
413413
original_column: original.original_column,
414414
name_index: original.name_index.and_then(|name_index| {
415-
name_index_mapping
416-
.borrow()
417-
.get(&name_index)
418-
.copied()
415+
name_index_mapping.borrow().get(&name_index).copied()
419416
}),
420417
}
421418
}),
@@ -590,10 +587,7 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
590587
original_line: original.original_line,
591588
original_column: original.original_column,
592589
name_index: original.name_index.and_then(|name_index| {
593-
name_index_mapping
594-
.borrow()
595-
.get(&name_index)
596-
.copied()
590+
name_index_mapping.borrow().get(&name_index).copied()
597591
}),
598592
}
599593
}),

0 commit comments

Comments
 (0)