Skip to content

Commit 77081b8

Browse files
committed
perf: rm SourceMapLineChunk
1 parent 9cca1a9 commit 77081b8

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

src/helpers.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -902,29 +902,7 @@ fn stream_chunks_of_source_map_lines_full<'a>(
902902
#[derive(Debug)]
903903
struct SourceMapLineData<'a> {
904904
pub mappings_data: Vec<i64>,
905-
pub chunks: Vec<SourceMapLineChunk<'a>>,
906-
}
907-
908-
#[derive(Debug)]
909-
struct SourceMapLineChunk<'a> {
910-
content: Cow<'a, str>,
911-
cached: OnceCell<WithIndices<Cow<'a, str>>>,
912-
}
913-
914-
impl<'a> SourceMapLineChunk<'a> {
915-
pub fn new(content: Cow<'a, str>) -> Self {
916-
Self {
917-
content,
918-
cached: OnceCell::new(),
919-
}
920-
}
921-
922-
pub fn substring(&self, start_index: usize, end_index: usize) -> &str {
923-
let cached = self
924-
.cached
925-
.get_or_init(|| WithIndices::new(self.content.clone()));
926-
cached.substring(start_index, end_index)
927-
}
905+
pub chunks: Vec<WithIndices<Cow<'a, str>>>,
928906
}
929907

930908
type InnerSourceIndexValueMapping<'a> =
@@ -1358,7 +1336,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
13581336
.unwrap_or(-1),
13591337
);
13601338
// SAFETY: final_source is false
1361-
let chunk = SourceMapLineChunk::new(chunk.unwrap());
1339+
let chunk = WithIndices::new(chunk.unwrap());
13621340
data.chunks.push(chunk);
13631341
},
13641342
&mut |i, source, source_content| {

src/replace_source.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
278278
RefCell::new(Vec::new());
279279
let name_mapping: RefCell<HashMap<Cow<str>, u32>> =
280280
RefCell::new(HashMap::default());
281-
let name_index_mapping: RefCell<Vec<u32>> = RefCell::new(Vec::new());
281+
let name_index_mapping: RefCell<HashMap<u32, u32>> =
282+
RefCell::new(HashMap::default());
282283

283284
// check if source_content[line][col] is equal to expect
284285
// Why this is needed?
@@ -404,10 +405,7 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
404405
original_line: original.original_line,
405406
original_column: original.original_column,
406407
name_index: original.name_index.and_then(|name_index| {
407-
name_index_mapping
408-
.borrow()
409-
.get(name_index as usize)
410-
.copied()
408+
name_index_mapping.borrow().get(&name_index).copied()
411409
}),
412410
}
413411
}),
@@ -582,10 +580,7 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
582580
original_line: original.original_line,
583581
original_column: original.original_column,
584582
name_index: original.name_index.and_then(|name_index| {
585-
name_index_mapping
586-
.borrow()
587-
.get(name_index as usize)
588-
.copied()
583+
name_index_mapping.borrow().get(&name_index).copied()
589584
}),
590585
}
591586
}),
@@ -614,7 +609,7 @@ impl<'a, T: Source> StreamChunks<'a> for ReplaceSource<T> {
614609
}
615610
name_index_mapping
616611
.borrow_mut()
617-
.insert(name_index as usize, global_index.unwrap());
612+
.insert(name_index, global_index.unwrap());
618613
},
619614
);
620615

0 commit comments

Comments
 (0)