Skip to content

Commit d27e830

Browse files
perf: skip range scan without range mappings
1 parent b19fc6d commit d27e830

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

crates/sourcemap/src/lib.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,14 @@ impl SourceMap {
822822
let source_map = build_source_map(&sources);
823823
let (mut mappings, line_offsets) = decode_mappings(raw.mappings)?;
824824

825-
if let Some(range_mappings_str) = raw.range_mappings
825+
let has_range_mappings = if let Some(range_mappings_str) = raw.range_mappings
826826
&& !range_mappings_str.is_empty()
827827
{
828828
decode_range_mappings(range_mappings_str, &mut mappings, &line_offsets)?;
829-
}
829+
mappings.iter().any(|m| m.is_range_mapping)
830+
} else {
831+
false
832+
};
830833

831834
let num_sources = sources.len();
832835
let scopes = match raw.scopes {
@@ -841,8 +844,6 @@ impl SourceMap {
841844
None => raw.x_google_ignore_list.unwrap_or_default(),
842845
};
843846

844-
let has_range_mappings = mappings.iter().any(|m| m.is_range_mapping);
845-
846847
Ok(Self {
847848
file: raw.file,
848849
source_root: raw.source_root,
@@ -897,11 +898,14 @@ impl SourceMap {
897898
let (mut mappings, line_offsets) = decode_mappings(raw.mappings)?;
898899

899900
// Decode range mappings if present
900-
if let Some(range_mappings_str) = raw.range_mappings
901+
let has_range_mappings = if let Some(range_mappings_str) = raw.range_mappings
901902
&& !range_mappings_str.is_empty()
902903
{
903904
decode_range_mappings(range_mappings_str, &mut mappings, &line_offsets)?;
904-
}
905+
mappings.iter().any(|m| m.is_range_mapping)
906+
} else {
907+
false
908+
};
905909

906910
// Decode scopes if present
907911
let num_sources = sources.len();
@@ -921,8 +925,6 @@ impl SourceMap {
921925
// Filter extensions to only keep x_* and x-* fields
922926
let extensions = filter_extensions(raw.extensions);
923927

924-
let has_range_mappings = mappings.iter().any(|m| m.is_range_mapping);
925-
926928
Ok(Self {
927929
file: raw.file,
928930
source_root: raw.source_root,
@@ -1598,13 +1600,15 @@ impl SourceMap {
15981600
range_mappings_str: Option<&str>,
15991601
) -> Result<Self, ParseError> {
16001602
let (mut mappings, line_offsets) = decode_mappings(mappings_str)?;
1601-
if let Some(rm_str) = range_mappings_str
1603+
let has_range_mappings = if let Some(rm_str) = range_mappings_str
16021604
&& !rm_str.is_empty()
16031605
{
16041606
decode_range_mappings(rm_str, &mut mappings, &line_offsets)?;
1605-
}
1607+
mappings.iter().any(|m| m.is_range_mapping)
1608+
} else {
1609+
false
1610+
};
16061611
let source_map = build_source_map(&sources);
1607-
let has_range_mappings = mappings.iter().any(|m| m.is_range_mapping);
16081612
Ok(Self {
16091613
file,
16101614
source_root,
@@ -1690,7 +1694,7 @@ impl SourceMap {
16901694
// Filter extensions to only keep x_* and x-* fields
16911695
let extensions = filter_extensions(raw.extensions);
16921696

1693-
let has_range_mappings = mappings.iter().any(|m| m.is_range_mapping);
1697+
let has_range_mappings = false;
16941698

16951699
Ok(Self {
16961700
file: raw.file,

0 commit comments

Comments
 (0)