Skip to content

Commit 61a0b82

Browse files
committed
perf: decode_mappings
1 parent 00cb1f4 commit 61a0b82

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/helpers.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ pub struct GeneratedInfo {
111111
pub generated_column: u32,
112112
}
113113

114-
pub fn decode_mappings<'b, 'a: 'b>(
114+
pub fn decode_mappings<'a>(
115115
source_map: &'a SourceMap,
116-
) -> impl Iterator<Item = Mapping> + 'b {
116+
) -> impl Iterator<Item = Mapping> + 'a {
117117
SegmentIter::new(source_map.mappings())
118118
}
119119

@@ -640,7 +640,7 @@ fn stream_chunks_of_source_map_final<'a>(
640640
}
641641
};
642642
for mapping in source_map.decoded_mappings() {
643-
on_mapping(mapping);
643+
on_mapping(&mapping);
644644
}
645645
result
646646
}
@@ -672,11 +672,11 @@ fn stream_chunks_of_source_map_full<'a>(
672672
let mut tracking_generated_column: u32 = 0;
673673
let mut tracking_mapping_original: Option<OriginalLocation> = None;
674674

675-
let mut mappings_iter = source_map.decoded_mappings().iter();
675+
let mut mappings_iter = source_map.decoded_mappings();
676676
let mut current_mapping = mappings_iter.next();
677677

678678
for (current_generated_index, c) in source.char_indices() {
679-
if let Some(mapping) = current_mapping {
679+
if let Some(mapping) = &current_mapping {
680680
if mapping.generated_line == current_generated_line
681681
&& mapping.generated_column == current_generated_column
682682
{
@@ -794,7 +794,7 @@ fn stream_chunks_of_source_map_lines_final<'a>(
794794
}
795795
};
796796
for mapping in source_map.decoded_mappings() {
797-
on_mapping(mapping);
797+
on_mapping(&mapping);
798798
}
799799
result
800800
}
@@ -864,7 +864,7 @@ fn stream_chunks_of_source_map_lines_full<'a>(
864864
}
865865
};
866866
for mapping in source_map.decoded_mappings() {
867-
on_mapping(mapping);
867+
on_mapping(&mapping);
868868
}
869869
while current_generated_line as usize <= lines.len() {
870870
let chunk = lines[current_generated_line as usize - 1];

src/source.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
convert::{TryFrom, TryInto},
55
fmt,
66
hash::{Hash, Hasher},
7-
sync::{Arc, OnceLock},
7+
sync::Arc,
88
};
99

1010
use dyn_clone::DynClone;
@@ -194,7 +194,6 @@ pub struct SourceMap {
194194
sources_content: Vec<Cow<'static, str>>,
195195
names: Vec<Cow<'static, str>>,
196196
source_root: Option<String>,
197-
decoded_mappings: OnceLock<Vec<Mapping>>,
198197
}
199198

200199
impl Hash for SourceMap {
@@ -224,7 +223,6 @@ impl SourceMap {
224223
sources_content,
225224
names,
226225
source_root: None,
227-
decoded_mappings: Default::default(),
228226
}
229227
}
230228

@@ -239,10 +237,8 @@ impl SourceMap {
239237
}
240238

241239
/// Get the decoded mappings in [SourceMap].
242-
pub fn decoded_mappings(&'_ self) -> &[Mapping] {
243-
self
244-
.decoded_mappings
245-
.get_or_init(|| decode_mappings(self).collect::<Vec<_>>())
240+
pub fn decoded_mappings<'a>(&'a self) -> impl Iterator<Item = Mapping> + 'a {
241+
decode_mappings(self)
246242
}
247243

248244
/// Get the mappings string in [SourceMap].
@@ -433,7 +429,6 @@ impl TryFrom<RawSourceMap> for SourceMap {
433429
sources_content,
434430
names,
435431
source_root: raw.source_root,
436-
decoded_mappings: Default::default(),
437432
})
438433
}
439434
}

0 commit comments

Comments
 (0)