@@ -12,6 +12,7 @@ define(function (require, exports, module) {
1212 var base64VLQ = require ( './base64-vlq' ) ;
1313 var util = require ( './util' ) ;
1414 var ArraySet = require ( './array-set' ) . ArraySet ;
15+ var MappingList = require ( './mapping-list' ) . MappingList ;
1516
1617 /**
1718 * An instance of the SourceMapGenerator represents a source map which is
@@ -29,7 +30,7 @@ define(function (require, exports, module) {
2930 this . _sourceRoot = util . getArg ( aArgs , 'sourceRoot' , null ) ;
3031 this . _sources = new ArraySet ( ) ;
3132 this . _names = new ArraySet ( ) ;
32- this . _mappings = [ ] ;
33+ this . _mappings = new MappingList ( ) ;
3334 this . _sourcesContents = null ;
3435 }
3536
@@ -109,7 +110,7 @@ define(function (require, exports, module) {
109110 this . _names . add ( name ) ;
110111 }
111112
112- this . _mappings . push ( {
113+ this . _mappings . add ( {
113114 generatedLine : generated . line ,
114115 generatedColumn : generated . column ,
115116 originalLine : original != null && original . line ,
@@ -186,7 +187,7 @@ define(function (require, exports, module) {
186187 var newNames = new ArraySet ( ) ;
187188
188189 // Find mappings for the "sourceFile"
189- this . _mappings . forEach ( function ( mapping ) {
190+ this . _mappings . unsortedForEach ( function ( mapping ) {
190191 if ( mapping . source === sourceFile && mapping . originalLine != null ) {
191192 // Check if it can be mapped by the source map, then update the mapping.
192193 var original = aSourceMapConsumer . originalPositionFor ( {
@@ -292,15 +293,10 @@ define(function (require, exports, module) {
292293 var result = '' ;
293294 var mapping ;
294295
295- // The mappings must be guaranteed to be in sorted order before we start
296- // serializing them or else the generated line numbers (which are defined
297- // via the ';' separators) will be all messed up. Note: it might be more
298- // performant to maintain the sorting as we insert them, rather than as we
299- // serialize them, but the big O is the same either way.
300- this . _mappings . sort ( util . compareByGeneratedPositions ) ;
296+ var mappings = this . _mappings . toArray ( ) ;
301297
302- for ( var i = 0 , len = this . _mappings . length ; i < len ; i ++ ) {
303- mapping = this . _mappings [ i ] ;
298+ for ( var i = 0 , len = mappings . length ; i < len ; i ++ ) {
299+ mapping = mappings [ i ] ;
304300
305301 if ( mapping . generatedLine !== previousGeneratedLine ) {
306302 previousGeneratedColumn = 0 ;
@@ -311,7 +307,7 @@ define(function (require, exports, module) {
311307 }
312308 else {
313309 if ( i > 0 ) {
314- if ( ! util . compareByGeneratedPositions ( mapping , this . _mappings [ i - 1 ] ) ) {
310+ if ( ! util . compareByGeneratedPositions ( mapping , mappings [ i - 1 ] ) ) {
315311 continue ;
316312 }
317313 result += ',' ;
0 commit comments