11use arrayvec:: ArrayVec ;
2- use rustc_hash:: FxHashMap as HashMap ;
32use std:: {
43 borrow:: { BorrowMut , Cow } ,
54 cell:: { OnceCell , RefCell } ,
65 rc:: Rc ,
76} ;
87
8+ use rustc_hash:: FxHashMap as HashMap ;
9+
910use crate :: {
1011 encoder:: create_encoder,
12+ linear_map:: LinearMap ,
1113 source:: { Mapping , OriginalLocation } ,
1214 vlq:: decode,
1315 with_indices:: WithIndices ,
@@ -16,7 +18,7 @@ use crate::{
1618
1719// Adding this type because sourceContentLine not happy
1820type InnerSourceContentLine < ' a > =
19- RefCell < HashMap < i64 , Option < Rc < Vec < WithIndices < & ' a str > > > > > > ;
21+ RefCell < HashMap < u32 , Option < Rc < Vec < WithIndices < & ' a str > > > > > > ;
2022
2123pub fn get_map < ' a , S : StreamChunks < ' a > > (
2224 stream : & ' a S ,
@@ -776,7 +778,7 @@ impl<'a> SourceMapLineChunk<'a> {
776778}
777779
778780type InnerSourceIndexValueMapping < ' a > =
779- HashMap < i64 , ( Cow < ' a , str > , Option < & ' a str > ) > ;
781+ LinearMap < ( Cow < ' a , str > , Option < & ' a str > ) > ;
780782
781783#[ allow( clippy:: too_many_arguments) ]
782784pub fn stream_chunks_of_combined_source_map < ' a > (
@@ -796,27 +798,28 @@ pub fn stream_chunks_of_combined_source_map<'a>(
796798 let source_mapping: RefCell < HashMap < Cow < str > , u32 > > =
797799 RefCell :: new ( HashMap :: default ( ) ) ;
798800 let mut name_mapping: HashMap < Cow < str > , u32 > = HashMap :: default ( ) ;
799- let source_index_mapping: RefCell < HashMap < i64 , i64 > > =
800- RefCell :: new ( HashMap :: default ( ) ) ;
801- let name_index_mapping: RefCell < HashMap < i64 , i64 > > =
802- RefCell :: new ( HashMap :: default ( ) ) ;
803- let name_index_value_mapping: RefCell < HashMap < i64 , Cow < str > > > =
804- RefCell :: new ( HashMap :: default ( ) ) ;
801+ let source_index_mapping: RefCell < LinearMap < i64 > > =
802+ RefCell :: new ( LinearMap :: default ( ) ) ;
803+ let name_index_mapping: RefCell < LinearMap < i64 > > =
804+ RefCell :: new ( LinearMap :: default ( ) ) ;
805+ let name_index_value_mapping: RefCell < LinearMap < Cow < str > > > =
806+ RefCell :: new ( LinearMap :: default ( ) ) ;
805807 let inner_source_index: RefCell < i64 > = RefCell :: new ( -2 ) ;
806- let inner_source_index_mapping: RefCell < HashMap < i64 , i64 > > =
807- RefCell :: new ( HashMap :: default ( ) ) ;
808+ let inner_source_index_mapping: RefCell < LinearMap < i64 > > =
809+ RefCell :: new ( LinearMap :: default ( ) ) ;
808810 let inner_source_index_value_mapping: RefCell < InnerSourceIndexValueMapping > =
809- RefCell :: new ( HashMap :: default ( ) ) ;
810- let inner_source_contents: RefCell < HashMap < i64 , Option < & str > > > =
811- RefCell :: new ( HashMap :: default ( ) ) ;
811+ RefCell :: new ( LinearMap :: default ( ) ) ;
812+ let inner_source_contents: RefCell < LinearMap < Option < & str > > > =
813+ RefCell :: new ( LinearMap :: default ( ) ) ;
812814 let inner_source_content_lines: InnerSourceContentLine =
813815 RefCell :: new ( HashMap :: default ( ) ) ;
814- let inner_name_index_mapping: RefCell < HashMap < i64 , i64 > > =
815- RefCell :: new ( HashMap :: default ( ) ) ;
816- let inner_name_index_value_mapping: RefCell < HashMap < i64 , Cow < str > > > =
817- RefCell :: new ( HashMap :: default ( ) ) ;
816+ let inner_name_index_mapping: RefCell < LinearMap < i64 > > =
817+ RefCell :: new ( LinearMap :: default ( ) ) ;
818+ let inner_name_index_value_mapping: RefCell < LinearMap < Cow < str > > > =
819+ RefCell :: new ( LinearMap :: default ( ) ) ;
818820 let inner_source_map_line_data: RefCell < Vec < SourceMapLineData > > =
819821 RefCell :: new ( Vec :: new ( ) ) ;
822+
820823 let find_inner_mapping = |line : i64 , column : i64 | -> Option < u32 > {
821824 let inner_source_map_line_data = inner_source_map_line_data. borrow ( ) ;
822825 if line as usize > inner_source_map_line_data. len ( ) {
@@ -864,6 +867,8 @@ pub fn stream_chunks_of_combined_source_map<'a>(
864867
865868 // Check if this is a mapping to the inner source
866869 if source_index == * inner_source_index. borrow ( ) {
870+ let source_index = source_index as u32 ;
871+
867872 // Check if there is a mapping in the inner source
868873 if let Some ( idx) = find_inner_mapping ( original_line, original_column) {
869874 let idx = idx as usize ;
@@ -877,6 +882,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
877882 let mut inner_original_column = mappings_data[ mi + 3 ] ;
878883 let mut inner_name_index = mappings_data[ mi + 4 ] ;
879884 if inner_source_index >= 0 {
885+ let inner_source_index = inner_source_index as u32 ;
880886 // Check for an identity mapping
881887 // where we are allowed to adjust the original column
882888 let inner_chunk = & chunks[ idx] ;
@@ -953,6 +959,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
953959 // emit name when needed and compute global name index
954960 let mut final_name_index = -1 ;
955961 if inner_name_index >= 0 {
962+ let inner_name_index = inner_name_index as u32 ;
956963 // when we have a inner name
957964 let mut inner_name_index_mapping =
958965 inner_name_index_mapping. borrow_mut ( ) ;
@@ -980,6 +987,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
980987 . insert ( inner_name_index, final_name_index) ;
981988 }
982989 } else if name_index >= 0 {
990+ let name_index = name_index as u32 ;
983991 // when we don't have an inner name,
984992 // but we have an outer name
985993 // it can be used when inner original code equals to the name
@@ -1094,11 +1102,16 @@ pub fn stream_chunks_of_combined_source_map<'a>(
10941102 }
10951103 }
10961104
1097- let final_source_index = source_index_mapping
1098- . borrow ( )
1099- . get ( & source_index)
1100- . copied ( )
1101- . unwrap_or ( -1 ) ;
1105+ let final_source_index = if source_index < 0 {
1106+ -1
1107+ } else {
1108+ let source_index = source_index as u32 ;
1109+ source_index_mapping
1110+ . borrow ( )
1111+ . get ( & source_index)
1112+ . copied ( )
1113+ . unwrap_or ( -1 )
1114+ } ;
11021115 if final_source_index < 0 {
11031116 // no source, so we make it a generated chunk
11041117 on_chunk (
@@ -1112,9 +1125,14 @@ pub fn stream_chunks_of_combined_source_map<'a>(
11121125 } else {
11131126 // Pass through the chunk with mapping
11141127 let mut name_index_mapping = name_index_mapping. borrow_mut ( ) ;
1115- let mut final_name_index =
1116- name_index_mapping. get ( & name_index) . copied ( ) . unwrap_or ( -1 ) ;
1128+ let mut final_name_index = if name_index >= 0 {
1129+ let name_index = name_index as u32 ;
1130+ name_index_mapping. get ( & name_index) . copied ( ) . unwrap_or ( -1 )
1131+ } else {
1132+ -1
1133+ } ;
11171134 if final_name_index == -2 {
1135+ let name_index = name_index as u32 ;
11181136 let name_index_value_mapping = name_index_value_mapping. borrow ( ) ;
11191137 let name = name_index_value_mapping. get ( & name_index) . unwrap ( ) ;
11201138 let mut global_index = name_mapping. get ( name) . copied ( ) ;
@@ -1144,9 +1162,8 @@ pub fn stream_chunks_of_combined_source_map<'a>(
11441162 }
11451163 } ,
11461164 & mut |i, source, mut source_content| {
1147- let i = i as i64 ;
11481165 if source == inner_source_name {
1149- * inner_source_index. borrow_mut ( ) = i;
1166+ * inner_source_index. borrow_mut ( ) = i as i64 ;
11501167 let mut inner_source = inner_source. borrow_mut ( ) ;
11511168 if let Some ( inner_source) = inner_source. as_ref ( ) {
11521169 source_content = Some ( inner_source) ;
@@ -1210,7 +1227,6 @@ pub fn stream_chunks_of_combined_source_map<'a>(
12101227 data. chunks . push ( chunk) ;
12111228 } ,
12121229 & mut |i, source, source_content| {
1213- let i = i as i64 ;
12141230 inner_source_contents
12151231 . borrow_mut ( )
12161232 . insert ( i, source_content. map ( Into :: into) ) ;
@@ -1221,7 +1237,6 @@ pub fn stream_chunks_of_combined_source_map<'a>(
12211237 . insert ( i, ( source, source_content) ) ;
12221238 } ,
12231239 & mut |i, name| {
1224- let i = i as i64 ;
12251240 inner_name_index_mapping. borrow_mut ( ) . insert ( i, -2 ) ;
12261241 inner_name_index_value_mapping. borrow_mut ( ) . insert ( i, name) ;
12271242 } ,
@@ -1245,7 +1260,6 @@ pub fn stream_chunks_of_combined_source_map<'a>(
12451260 }
12461261 } ,
12471262 & mut |i, name| {
1248- let i = i as i64 ;
12491263 name_index_mapping. borrow_mut ( ) . insert ( i, -2 ) ;
12501264 name_index_value_mapping. borrow_mut ( ) . insert ( i, name) ;
12511265 } ,
0 commit comments