@@ -35,7 +35,7 @@ pub fn get_map<'a, S: StreamChunks<'a>>(
35
35
mappings. push ( mapping) ;
36
36
} ,
37
37
// on_source
38
- & mut |source_index, source : & str , source_content : Option < & str > | {
38
+ & mut |source_index, source, source_content| {
39
39
let source_index = source_index as usize ;
40
40
if sources. len ( ) <= source_index {
41
41
sources. resize ( source_index + 1 , Cow :: Borrowed ( "" ) ) ;
@@ -49,7 +49,7 @@ pub fn get_map<'a, S: StreamChunks<'a>>(
49
49
}
50
50
} ,
51
51
// on_name
52
- & mut |name_index, name : & str | {
52
+ & mut |name_index, name| {
53
53
let name_index = name_index as usize ;
54
54
if names. len ( ) <= name_index {
55
55
names. resize ( name_index + 1 , Cow :: Borrowed ( "" ) ) ;
@@ -78,7 +78,7 @@ pub trait StreamChunks<'a> {
78
78
pub type OnChunk < ' a , ' b > = & ' a mut dyn FnMut ( Option < & ' b str > , Mapping ) ;
79
79
80
80
/// [OnSource] abstraction, see [webpack-sources onSource](https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/helpers/streamChunks.js#L13).
81
- pub type OnSource < ' a , ' b > = & ' a mut dyn FnMut ( u32 , & str , Option < & ' b str > ) ;
81
+ pub type OnSource < ' a , ' b > = & ' a mut dyn FnMut ( u32 , Cow < ' b , str > , Option < & ' b str > ) ;
82
82
83
83
/// [OnName] abstraction, see [webpack-sources onName](https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/helpers/streamChunks.js#L13).
84
84
pub type OnName < ' a , ' b > = & ' a mut dyn FnMut ( u32 , & ' b str ) ;
@@ -580,13 +580,13 @@ pub fn stream_chunks_of_source_map<'a>(
580
580
}
581
581
}
582
582
583
- fn get_source ( source_map : & SourceMap , source : & str ) -> String {
583
+ fn get_source < ' a > ( source_map : & SourceMap , source : & ' a str ) -> Cow < ' a , str > {
584
584
let source_root = source_map. source_root ( ) ;
585
585
match source_root {
586
- Some ( root) if root. is_empty ( ) => source . to_string ( ) ,
587
- Some ( root) if root. ends_with ( '/' ) => format ! ( "{}{}" , root, source) ,
588
- Some ( root) => format ! ( "{}/{}" , root, source) ,
589
- None => source . to_string ( ) ,
586
+ Some ( root) if root. is_empty ( ) => Cow :: Borrowed ( source ) ,
587
+ Some ( root) if root. ends_with ( '/' ) => Cow :: Owned ( format ! ( "{}{}" , root, source) ) ,
588
+ Some ( root) => Cow :: Owned ( format ! ( "{}/{}" , root, source) ) ,
589
+ None => Cow :: Borrowed ( source ) ,
590
590
}
591
591
}
592
592
@@ -604,7 +604,7 @@ fn stream_chunks_of_source_map_final<'a>(
604
604
for ( i, source) in source_map. sources ( ) . iter ( ) . enumerate ( ) {
605
605
on_source (
606
606
i as u32 ,
607
- & get_source ( source_map, source) ,
607
+ get_source ( source_map, source) ,
608
608
source_map. get_source_content ( i) ,
609
609
)
610
610
}
@@ -656,7 +656,7 @@ fn stream_chunks_of_source_map_full<'a>(
656
656
for ( i, source) in source_map. sources ( ) . iter ( ) . enumerate ( ) {
657
657
on_source (
658
658
i as u32 ,
659
- & get_source ( source_map, source) ,
659
+ get_source ( source_map, source) ,
660
660
source_map. get_source_content ( i) ,
661
661
)
662
662
}
@@ -764,7 +764,7 @@ fn stream_chunks_of_source_map_lines_final<'a>(
764
764
for ( i, source) in source_map. sources ( ) . iter ( ) . enumerate ( ) {
765
765
on_source (
766
766
i as u32 ,
767
- & get_source ( source_map, source) ,
767
+ get_source ( source_map, source) ,
768
768
source_map. get_source_content ( i) ,
769
769
)
770
770
}
@@ -819,7 +819,7 @@ fn stream_chunks_of_source_map_lines_full<'a>(
819
819
for ( i, source) in source_map. sources ( ) . iter ( ) . enumerate ( ) {
820
820
on_source (
821
821
i as u32 ,
822
- & get_source ( source_map, source) ,
822
+ get_source ( source_map, source) ,
823
823
source_map. get_source_content ( i) ,
824
824
)
825
825
}
@@ -918,6 +918,8 @@ impl<'a> SourceMapLineChunk<'a> {
918
918
}
919
919
}
920
920
921
+ type InnerSourceIndexValueMapping < ' a > = HashMap < i64 , ( Cow < ' a , str > , Option < & ' a str > ) > ;
922
+
921
923
#[ allow( clippy:: too_many_arguments) ]
922
924
pub fn stream_chunks_of_combined_source_map < ' a > (
923
925
source : & ' a str ,
@@ -933,7 +935,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
933
935
) -> GeneratedInfo {
934
936
let on_source = RefCell :: new ( on_source) ;
935
937
let inner_source: RefCell < Option < & str > > = RefCell :: new ( inner_source) ;
936
- let source_mapping: RefCell < HashMap < String , u32 > > =
938
+ let source_mapping: RefCell < HashMap < Cow < str > , u32 > > =
937
939
RefCell :: new ( HashMap :: default ( ) ) ;
938
940
let mut name_mapping: HashMap < & str , u32 > = HashMap :: default ( ) ;
939
941
let source_index_mapping: RefCell < HashMap < i64 , i64 > > =
@@ -945,9 +947,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
945
947
let inner_source_index: RefCell < i64 > = RefCell :: new ( -2 ) ;
946
948
let inner_source_index_mapping: RefCell < HashMap < i64 , i64 > > =
947
949
RefCell :: new ( HashMap :: default ( ) ) ;
948
- let inner_source_index_value_mapping: RefCell <
949
- HashMap < i64 , ( String , Option < & str > ) > ,
950
- > = RefCell :: new ( HashMap :: default ( ) ) ;
950
+ let inner_source_index_value_mapping: RefCell < InnerSourceIndexValueMapping > = RefCell :: new ( HashMap :: default ( ) ) ;
951
951
let inner_source_contents: RefCell < HashMap < i64 , Option < & str > > > =
952
952
RefCell :: new ( HashMap :: default ( ) ) ;
953
953
let inner_source_content_lines: InnerSourceContentLine =
@@ -1080,11 +1080,11 @@ pub fn stream_chunks_of_combined_source_map<'a>(
1080
1080
. unwrap_or ( ( "" . into ( ) , None ) ) ;
1081
1081
let mut source_mapping = source_mapping. borrow_mut ( ) ;
1082
1082
let mut global_index =
1083
- source_mapping. get ( & source. to_string ( ) ) . copied ( ) ;
1083
+ source_mapping. get ( & source) . copied ( ) ;
1084
1084
if global_index. is_none ( ) {
1085
1085
let len = source_mapping. len ( ) as u32 ;
1086
- source_mapping. insert ( source. to_string ( ) , len) ;
1087
- on_source. borrow_mut ( ) ( len, & source, source_content) ;
1086
+ source_mapping. insert ( source. clone ( ) , len) ;
1087
+ on_source. borrow_mut ( ) ( len, source, source_content) ;
1088
1088
global_index = Some ( len) ;
1089
1089
}
1090
1090
source_index = global_index. unwrap ( ) as i64 ;
@@ -1225,7 +1225,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
1225
1225
source_mapping. insert ( source. into ( ) , len) ;
1226
1226
on_source. borrow_mut ( ) (
1227
1227
len,
1228
- inner_source_name,
1228
+ Cow :: Borrowed ( inner_source_name) ,
1229
1229
* inner_source. borrow ( ) ,
1230
1230
) ;
1231
1231
global_index = Some ( len) ;
@@ -1360,7 +1360,7 @@ pub fn stream_chunks_of_combined_source_map<'a>(
1360
1360
inner_source_index_mapping. borrow_mut ( ) . insert ( i, -2 ) ;
1361
1361
inner_source_index_value_mapping
1362
1362
. borrow_mut ( )
1363
- . insert ( i, ( source. to_string ( ) , source_content) ) ;
1363
+ . insert ( i, ( source, source_content) ) ;
1364
1364
} ,
1365
1365
& mut |i, name| {
1366
1366
let i = i as i64 ;
@@ -1374,10 +1374,10 @@ pub fn stream_chunks_of_combined_source_map<'a>(
1374
1374
) ;
1375
1375
} else {
1376
1376
let mut source_mapping = source_mapping. borrow_mut ( ) ;
1377
- let mut global_index = source_mapping. get ( source) . copied ( ) ;
1377
+ let mut global_index = source_mapping. get ( & source) . copied ( ) ;
1378
1378
if global_index. is_none ( ) {
1379
1379
let len = source_mapping. len ( ) as u32 ;
1380
- source_mapping. insert ( source. to_string ( ) , len) ;
1380
+ source_mapping. insert ( source. clone ( ) , len) ;
1381
1381
on_source. borrow_mut ( ) ( len, source, source_content) ;
1382
1382
global_index = Some ( len) ;
1383
1383
}
0 commit comments