@@ -267,7 +267,9 @@ return /******/ (function(modules) { // webpackBootstrap
267267 }
268268 // Applying the SourceMap can add and remove items from the sources and
269269 // the names array.
270- var newSources = new ArraySet ( ) ;
270+ var newSources = this . _mappings . toArray ( ) . length > 0
271+ ? new ArraySet ( )
272+ : this . _sources ;
271273 var newNames = new ArraySet ( ) ;
272274
273275 // Find mappings for the "sourceFile"
@@ -786,6 +788,43 @@ return /******/ (function(modules) { // webpackBootstrap
786788 }
787789 exports . urlGenerate = urlGenerate ;
788790
791+ const MAX_CACHED_INPUTS = 32 ;
792+
793+ /**
794+ * Takes some function `f(input) -> result` and returns a memoized version of
795+ * `f`.
796+ *
797+ * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
798+ * memoization is a dumb-simple, linear least-recently-used cache.
799+ */
800+ function lruMemoize ( f ) {
801+ const cache = [ ] ;
802+
803+ return function ( input ) {
804+ for ( var i = 0 ; i < cache . length ; i ++ ) {
805+ if ( cache [ i ] . input === input ) {
806+ var temp = cache [ 0 ] ;
807+ cache [ 0 ] = cache [ i ] ;
808+ cache [ i ] = temp ;
809+ return cache [ 0 ] . result ;
810+ }
811+ }
812+
813+ var result = f ( input ) ;
814+
815+ cache . unshift ( {
816+ input,
817+ result,
818+ } ) ;
819+
820+ if ( cache . length > MAX_CACHED_INPUTS ) {
821+ cache . pop ( ) ;
822+ }
823+
824+ return result ;
825+ } ;
826+ }
827+
789828 /**
790829 * Normalizes a path, or the path portion of a URL:
791830 *
@@ -797,7 +836,7 @@ return /******/ (function(modules) { // webpackBootstrap
797836 *
798837 * @param aPath The path or url to normalize.
799838 */
800- function normalize ( aPath ) {
839+ var normalize = lruMemoize ( function normalize ( aPath ) {
801840 var path = aPath ;
802841 var url = urlParse ( aPath ) ;
803842 if ( url ) {
@@ -808,7 +847,25 @@ return /******/ (function(modules) { // webpackBootstrap
808847 }
809848 var isAbsolute = exports . isAbsolute ( path ) ;
810849
811- var parts = path . split ( / \/ + / ) ;
850+ // Split the path into parts between `/` characters. This is much faster than
851+ // using `.split(/\/+/g)`.
852+ var parts = [ ] ;
853+ var start = 0 ;
854+ var i = 0 ;
855+ while ( true ) {
856+ start = i ;
857+ i = path . indexOf ( "/" , start ) ;
858+ if ( i === - 1 ) {
859+ parts . push ( path . slice ( start ) ) ;
860+ break ;
861+ } else {
862+ parts . push ( path . slice ( start , i ) ) ;
863+ while ( i < path . length && path [ i ] === "/" ) {
864+ i ++ ;
865+ }
866+ }
867+ }
868+
812869 for ( var part , up = 0 , i = parts . length - 1 ; i >= 0 ; i -- ) {
813870 part = parts [ i ] ;
814871 if ( part === '.' ) {
@@ -839,7 +896,7 @@ return /******/ (function(modules) { // webpackBootstrap
839896 return urlGenerate ( url ) ;
840897 }
841898 return path ;
842- }
899+ } ) ;
843900 exports . normalize = normalize ;
844901
845902 /**
@@ -1493,7 +1550,7 @@ return /******/ (function(modules) { // webpackBootstrap
14931550 enumerable : true ,
14941551 get : function ( ) {
14951552 if ( ! this . __generatedMappings ) {
1496- this . _parseMappings ( this . _mappings , this . sourceRoot ) ;
1553+ this . _sortGeneratedMappings ( ) ;
14971554 }
14981555
14991556 return this . __generatedMappings ;
@@ -1506,13 +1563,39 @@ return /******/ (function(modules) { // webpackBootstrap
15061563 enumerable : true ,
15071564 get : function ( ) {
15081565 if ( ! this . __originalMappings ) {
1509- this . _parseMappings ( this . _mappings , this . sourceRoot ) ;
1566+ this . _sortOriginalMappings ( ) ;
15101567 }
15111568
15121569 return this . __originalMappings ;
15131570 }
15141571 } ) ;
15151572
1573+ SourceMapConsumer . prototype . __generatedMappingsUnsorted = null ;
1574+ Object . defineProperty ( SourceMapConsumer . prototype , '_generatedMappingsUnsorted' , {
1575+ configurable : true ,
1576+ enumerable : true ,
1577+ get : function ( ) {
1578+ if ( ! this . __generatedMappingsUnsorted ) {
1579+ this . _parseMappings ( this . _mappings , this . sourceRoot ) ;
1580+ }
1581+
1582+ return this . __generatedMappingsUnsorted ;
1583+ }
1584+ } ) ;
1585+
1586+ SourceMapConsumer . prototype . __originalMappingsUnsorted = null ;
1587+ Object . defineProperty ( SourceMapConsumer . prototype , '_originalMappingsUnsorted' , {
1588+ configurable : true ,
1589+ enumerable : true ,
1590+ get : function ( ) {
1591+ if ( ! this . __originalMappingsUnsorted ) {
1592+ this . _parseMappings ( this . _mappings , this . sourceRoot ) ;
1593+ }
1594+
1595+ return this . __originalMappingsUnsorted ;
1596+ }
1597+ } ) ;
1598+
15161599 SourceMapConsumer . prototype . _charIsMappingSeparator =
15171600 function SourceMapConsumer_charIsMappingSeparator ( aStr , index ) {
15181601 var c = aStr . charAt ( index ) ;
@@ -1529,6 +1612,20 @@ return /******/ (function(modules) { // webpackBootstrap
15291612 throw new Error ( "Subclasses must implement _parseMappings" ) ;
15301613 } ;
15311614
1615+ SourceMapConsumer . prototype . _sortGeneratedMappings =
1616+ function SourceMapConsumer_sortGeneratedMappings ( ) {
1617+ const mappings = this . _generatedMappingsUnsorted ;
1618+ quickSort ( mappings , util . compareByGeneratedPositionsDeflated ) ;
1619+ this . __generatedMappings = mappings ;
1620+ } ;
1621+
1622+ SourceMapConsumer . prototype . _sortOriginalMappings =
1623+ function SourceMapConsumer_sortOriginalMappings ( ) {
1624+ const mappings = this . _originalMappingsUnsorted ;
1625+ quickSort ( mappings , util . compareByOriginalPositions ) ;
1626+ this . __originalMappings = mappings ;
1627+ } ;
1628+
15321629 SourceMapConsumer . GENERATED_ORDER = 1 ;
15331630 SourceMapConsumer . ORIGINAL_ORDER = 2 ;
15341631
@@ -1570,8 +1667,11 @@ return /******/ (function(modules) { // webpackBootstrap
15701667
15711668 var sourceRoot = this . sourceRoot ;
15721669 mappings . map ( function ( mapping ) {
1573- var source = mapping . source === null ? null : this . _sources . at ( mapping . source ) ;
1574- source = util . computeSourceURL ( sourceRoot , source , this . _sourceMapURL ) ;
1670+ var source = null ;
1671+ if ( mapping . source !== null ) {
1672+ source = this . _sources . at ( mapping . source ) ;
1673+ source = util . computeSourceURL ( sourceRoot , source , this . _sourceMapURL ) ;
1674+ }
15751675 return {
15761676 source : source ,
15771677 generatedLine : mapping . generatedLine ,
@@ -1987,11 +2087,9 @@ return /******/ (function(modules) { // webpackBootstrap
19872087 }
19882088 }
19892089
1990- quickSort ( generatedMappings , util . compareByGeneratedPositionsDeflated ) ;
1991- this . __generatedMappings = generatedMappings ;
2090+ this . __generatedMappingsUnsorted = generatedMappings ;
19922091
1993- quickSort ( originalMappings , util . compareByOriginalPositions ) ;
1994- this . __originalMappings = originalMappings ;
2092+ this . __originalMappingsUnsorted = originalMappings ;
19952093 } ;
19962094
19972095 /**
@@ -2520,8 +2618,8 @@ return /******/ (function(modules) { // webpackBootstrap
25202618 */
25212619 IndexedSourceMapConsumer . prototype . _parseMappings =
25222620 function IndexedSourceMapConsumer_parseMappings ( aStr , aSourceRoot ) {
2523- this . __generatedMappings = [ ] ;
2524- this . __originalMappings = [ ] ;
2621+ const generatedMappings = this . __generatedMappingsUnsorted = [ ] ;
2622+ const originalMappings = this . __originalMappingsUnsorted = [ ] ;
25252623 for ( var i = 0 ; i < this . _sections . length ; i ++ ) {
25262624 var section = this . _sections [ i ] ;
25272625 var sectionMappings = section . consumer . _generatedMappings ;
@@ -2557,15 +2655,12 @@ return /******/ (function(modules) { // webpackBootstrap
25572655 name : name
25582656 } ;
25592657
2560- this . __generatedMappings . push ( adjustedMapping ) ;
2658+ generatedMappings . push ( adjustedMapping ) ;
25612659 if ( typeof adjustedMapping . originalLine === 'number' ) {
2562- this . __originalMappings . push ( adjustedMapping ) ;
2660+ originalMappings . push ( adjustedMapping ) ;
25632661 }
25642662 }
25652663 }
2566-
2567- quickSort ( this . __generatedMappings , util . compareByGeneratedPositionsDeflated ) ;
2568- quickSort ( this . __originalMappings , util . compareByOriginalPositions ) ;
25692664 } ;
25702665
25712666 exports . IndexedSourceMapConsumer = IndexedSourceMapConsumer ;
0 commit comments