@@ -81,23 +81,57 @@ export default class SourceMap {
81
81
* @param columnOffset an offset that gets added to the sourceColumn index of each mapping
82
82
*/
83
83
addIndexedMapping ( mapping : IndexedMapping < string > , lineOffset ?: number = 0 , columnOffset ?: number = 0 ) : void {
84
- let hasValidOriginal =
85
- mapping . original &&
86
- typeof mapping . original . line === 'number' &&
87
- ! isNaN ( mapping . original . line ) &&
88
- typeof mapping . original . column === 'number' &&
89
- ! isNaN ( mapping . original . column ) ;
90
-
91
- this . sourceMapInstance . addIndexedMapping (
92
- mapping . generated . line + lineOffset - 1 ,
93
- mapping . generated . column + columnOffset ,
84
+ // Not sure if it'll be worth it to add this back to C++, wrapping it in an array probably doesn't do that much harm in JS?
85
+ // Also we barely use this function anyway...
86
+ this. addIndexedMappings ( [ mapping ] , lineOffset , columnOffset ) ;
87
+ }
88
+
89
+ _indexedMappingsToInt32Array (
90
+ mappings : Array < IndexedMapping < string >> ,
91
+ lineOffset ?: number = 0 ,
92
+ columnOffset ?: number = 0
93
+ ) {
94
+ // Encode all mappings into a single typed array and make one call
95
+ // to C++ instead of one for each mapping to improve performance.
96
+ let mappingBuffer = new Int32Array ( mappings . length * 6 ) ;
97
+ let sources : Map < string , number > = new Map ( ) ;
98
+ let names : Map < string , number > = new Map ( ) ;
99
+ let i = 0 ;
100
+ for ( let mapping of mappings ) {
101
+ let hasValidOriginal =
102
+ mapping . original &&
103
+ typeof mapping . original . line === 'number' &&
104
+ ! isNaN ( mapping . original . line ) &&
105
+ typeof mapping . original . column === 'number' &&
106
+ ! isNaN ( mapping . original . column ) ;
107
+
108
+ mappingBuffer [ i ++ ] = mapping . generated . line + lineOffset - 1 ;
109
+ mappingBuffer [ i ++ ] = mapping . generated . column + columnOffset ;
94
110
// $FlowFixMe
95
- hasValidOriginal ? mapping . original . line - 1 : - 1 ,
111
+ mappingBuffer [ i ++ ] = hasValidOriginal ? mapping . original . line - 1 : - 1 ;
96
112
// $FlowFixMe
97
- hasValidOriginal ? mapping . original . column : - 1 ,
98
- mapping . source ? relatifyPath ( mapping . source , this . projectRoot ) : '' ,
99
- mapping . name || ''
100
- ) ;
113
+ mappingBuffer [ i ++ ] = hasValidOriginal ? mapping . original . column : - 1 ;
114
+
115
+ let sourceIndex = mapping . source ? sources . get ( mapping . source ) : - 1 ;
116
+ if ( sourceIndex == null ) {
117
+ // $FlowFixMe
118
+ sourceIndex = this . addSource ( mapping . source ) ;
119
+ // $FlowFixMe
120
+ sources . set ( mapping . source , sourceIndex ) ;
121
+ }
122
+ mappingBuffer [ i ++ ] = sourceIndex ;
123
+
124
+ let nameIndex = mapping . name ? names . get ( mapping . name ) : - 1 ;
125
+ if ( nameIndex == null ) {
126
+ // $FlowFixMe
127
+ nameIndex = this . addName ( mapping . name ) ;
128
+ // $FlowFixMe
129
+ names . set ( mapping . name , nameIndex ) ;
130
+ }
131
+ mappingBuffer [ i ++ ] = nameIndex ;
132
+ }
133
+
134
+ return mappingBuffer ;
101
135
}
102
136
103
137
/**
@@ -116,10 +150,7 @@ export default class SourceMap {
116
150
lineOffset ? : number = 0 ,
117
151
columnOffset ? : number = 0
118
152
) : SourceMap {
119
- for ( let mapping of mappings ) {
120
- this . addIndexedMapping ( mapping , lineOffset , columnOffset ) ;
121
- }
122
- return this ;
153
+ throw new Error ( 'Should be implemented by child class' ) ;
123
154
}
124
155
125
156
/**
0 commit comments