11use arrayvec:: ArrayVec ;
2- use rustc_hash:: FxHashMap as HashMap ;
32use std:: {
43 borrow:: { BorrowMut , Cow } ,
54 cell:: 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 ,
@@ -747,7 +749,7 @@ struct SourceMapLineData<'a> {
747749}
748750
749751type InnerSourceIndexValueMapping < ' a > =
750- HashMap < i64 , ( Cow < ' a , str > , Option < & ' a str > ) > ;
752+ LinearMap < ( Cow < ' a , str > , Option < & ' a str > ) > ;
751753
752754#[ allow( clippy:: too_many_arguments) ]
753755pub fn stream_chunks_of_combined_source_map < ' a > (
@@ -767,27 +769,28 @@ pub fn stream_chunks_of_combined_source_map<'a>(
767769 let source_mapping: RefCell < HashMap < Cow < str > , u32 > > =
768770 RefCell :: new ( HashMap :: default ( ) ) ;
769771 let mut name_mapping: HashMap < Cow < str > , u32 > = HashMap :: default ( ) ;
770- let source_index_mapping: RefCell < HashMap < i64 , i64 > > =
771- RefCell :: new ( HashMap :: default ( ) ) ;
772- let name_index_mapping: RefCell < HashMap < i64 , i64 > > =
773- RefCell :: new ( HashMap :: default ( ) ) ;
774- let name_index_value_mapping: RefCell < HashMap < i64 , Cow < str > > > =
775- RefCell :: new ( HashMap :: default ( ) ) ;
772+ let source_index_mapping: RefCell < LinearMap < i64 > > =
773+ RefCell :: new ( LinearMap :: default ( ) ) ;
774+ let name_index_mapping: RefCell < LinearMap < i64 > > =
775+ RefCell :: new ( LinearMap :: default ( ) ) ;
776+ let name_index_value_mapping: RefCell < LinearMap < Cow < str > > > =
777+ RefCell :: new ( LinearMap :: default ( ) ) ;
776778 let inner_source_index: RefCell < i64 > = RefCell :: new ( -2 ) ;
777- let inner_source_index_mapping: RefCell < HashMap < i64 , i64 > > =
778- RefCell :: new ( HashMap :: default ( ) ) ;
779+ let inner_source_index_mapping: RefCell < LinearMap < i64 > > =
780+ RefCell :: new ( LinearMap :: default ( ) ) ;
779781 let inner_source_index_value_mapping: RefCell < InnerSourceIndexValueMapping > =
780- RefCell :: new ( HashMap :: default ( ) ) ;
781- let inner_source_contents: RefCell < HashMap < i64 , Option < & str > > > =
782- RefCell :: new ( HashMap :: default ( ) ) ;
782+ RefCell :: new ( LinearMap :: default ( ) ) ;
783+ let inner_source_contents: RefCell < LinearMap < Option < & str > > > =
784+ RefCell :: new ( LinearMap :: default ( ) ) ;
783785 let inner_source_content_lines: InnerSourceContentLine =
784786 RefCell :: new ( HashMap :: default ( ) ) ;
785- let inner_name_index_mapping: RefCell < HashMap < i64 , i64 > > =
786- RefCell :: new ( HashMap :: default ( ) ) ;
787- let inner_name_index_value_mapping: RefCell < HashMap < i64 , Cow < str > > > =
788- RefCell :: new ( HashMap :: default ( ) ) ;
787+ let inner_name_index_mapping: RefCell < LinearMap < i64 > > =
788+ RefCell :: new ( LinearMap :: default ( ) ) ;
789+ let inner_name_index_value_mapping: RefCell < LinearMap < Cow < str > > > =
790+ RefCell :: new ( LinearMap :: default ( ) ) ;
789791 let inner_source_map_line_data: RefCell < Vec < SourceMapLineData > > =
790792 RefCell :: new ( Vec :: new ( ) ) ;
793+
791794 let find_inner_mapping = |line : i64 , column : i64 | -> Option < u32 > {
792795 let inner_source_map_line_data = inner_source_map_line_data. borrow ( ) ;
793796 if line as usize > inner_source_map_line_data. len ( ) {
@@ -835,6 +838,8 @@ pub fn stream_chunks_of_combined_source_map<'a>(
835838
836839 // Check if this is a mapping to the inner source
837840 if source_index == * inner_source_index. borrow ( ) {
841+ let source_index = source_index as u32 ;
842+
838843 // Check if there is a mapping in the inner source
839844 if let Some ( idx) = find_inner_mapping ( original_line, original_column) {
840845 let idx = idx as usize ;
@@ -848,6 +853,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
848853 let mut inner_original_column = mappings_data[ mi + 3 ] ;
849854 let mut inner_name_index = mappings_data[ mi + 4 ] ;
850855 if inner_source_index >= 0 {
856+ let inner_source_index = inner_source_index as u32 ;
851857 // Check for an identity mapping
852858 // where we are allowed to adjust the original column
853859 let inner_chunk = & chunks[ idx] ;
@@ -924,6 +930,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
924930 // emit name when needed and compute global name index
925931 let mut final_name_index = -1 ;
926932 if inner_name_index >= 0 {
933+ let inner_name_index = inner_name_index as u32 ;
927934 // when we have a inner name
928935 let mut inner_name_index_mapping =
929936 inner_name_index_mapping. borrow_mut ( ) ;
@@ -951,6 +958,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
951958 . insert ( inner_name_index, final_name_index) ;
952959 }
953960 } else if name_index >= 0 {
961+ let name_index = name_index as u32 ;
954962 // when we don't have an inner name,
955963 // but we have an outer name
956964 // it can be used when inner original code equals to the name
@@ -1065,11 +1073,16 @@ pub fn stream_chunks_of_combined_source_map<'a>(
10651073 }
10661074 }
10671075
1068- let final_source_index = source_index_mapping
1069- . borrow ( )
1070- . get ( & source_index)
1071- . copied ( )
1072- . unwrap_or ( -1 ) ;
1076+ let final_source_index = if source_index < 0 {
1077+ -1
1078+ } else {
1079+ let source_index = source_index as u32 ;
1080+ source_index_mapping
1081+ . borrow ( )
1082+ . get ( & source_index)
1083+ . copied ( )
1084+ . unwrap_or ( -1 )
1085+ } ;
10731086 if final_source_index < 0 {
10741087 // no source, so we make it a generated chunk
10751088 on_chunk (
@@ -1083,9 +1096,14 @@ pub fn stream_chunks_of_combined_source_map<'a>(
10831096 } else {
10841097 // Pass through the chunk with mapping
10851098 let mut name_index_mapping = name_index_mapping. borrow_mut ( ) ;
1086- let mut final_name_index =
1087- name_index_mapping. get ( & name_index) . copied ( ) . unwrap_or ( -1 ) ;
1099+ let mut final_name_index = if name_index >= 0 {
1100+ let name_index = name_index as u32 ;
1101+ name_index_mapping. get ( & name_index) . copied ( ) . unwrap_or ( -1 )
1102+ } else {
1103+ -1
1104+ } ;
10881105 if final_name_index == -2 {
1106+ let name_index = name_index as u32 ;
10891107 let name_index_value_mapping = name_index_value_mapping. borrow ( ) ;
10901108 let name = name_index_value_mapping. get ( & name_index) . unwrap ( ) ;
10911109 let mut global_index = name_mapping. get ( name) . copied ( ) ;
@@ -1115,9 +1133,8 @@ pub fn stream_chunks_of_combined_source_map<'a>(
11151133 }
11161134 } ,
11171135 & mut |i, source, mut source_content| {
1118- let i = i as i64 ;
11191136 if source == inner_source_name {
1120- * inner_source_index. borrow_mut ( ) = i;
1137+ * inner_source_index. borrow_mut ( ) = i as i64 ;
11211138 let mut inner_source = inner_source. borrow_mut ( ) ;
11221139 if let Some ( inner_source) = inner_source. as_ref ( ) {
11231140 source_content = Some ( inner_source) ;
@@ -1181,7 +1198,6 @@ pub fn stream_chunks_of_combined_source_map<'a>(
11811198 data. chunks . push ( chunk) ;
11821199 } ,
11831200 & mut |i, source, source_content| {
1184- let i = i as i64 ;
11851201 inner_source_contents
11861202 . borrow_mut ( )
11871203 . insert ( i, source_content. map ( Into :: into) ) ;
@@ -1192,7 +1208,6 @@ pub fn stream_chunks_of_combined_source_map<'a>(
11921208 . insert ( i, ( source, source_content) ) ;
11931209 } ,
11941210 & mut |i, name| {
1195- let i = i as i64 ;
11961211 inner_name_index_mapping. borrow_mut ( ) . insert ( i, -2 ) ;
11971212 inner_name_index_value_mapping. borrow_mut ( ) . insert ( i, name) ;
11981213 } ,
@@ -1216,7 +1231,6 @@ pub fn stream_chunks_of_combined_source_map<'a>(
12161231 }
12171232 } ,
12181233 & mut |i, name| {
1219- let i = i as i64 ;
12201234 name_index_mapping. borrow_mut ( ) . insert ( i, -2 ) ;
12211235 name_index_value_mapping. borrow_mut ( ) . insert ( i, name) ;
12221236 } ,
0 commit comments