@@ -566,6 +566,21 @@ namespace ts {
566566 return result ;
567567 }
568568
569+ /**
570+ * Adds the value to an array of values associated with the key, and returns the array.
571+ * Creates the array if it does not already exist.
572+ */
573+ export function multiMapAdd < V > ( map : Map < V [ ] > , key : string , value : V ) : V [ ] {
574+ const values = map [ key ] ;
575+ if ( values ) {
576+ values . push ( value ) ;
577+ return values ;
578+ }
579+ else {
580+ return map [ key ] = [ value ] ;
581+ }
582+ }
583+
569584 /**
570585 * Tests whether a value is an array.
571586 */
@@ -1500,20 +1515,39 @@ namespace ts {
15001515 }
15011516 }
15021517
1503- export function copyListRemovingItem < T > ( item : T , list : T [ ] ) {
1504- const copiedList : T [ ] = [ ] ;
1505- for ( const e of list ) {
1506- if ( e !== item ) {
1507- copiedList . push ( e ) ;
1518+ /** Remove an item from an array, moving everything to its right one space left. */
1519+ export function orderedRemoveItemAt < T > ( array : T [ ] , index : number ) : void {
1520+ // This seems to be faster than either `array.splice(i, 1)` or `array.copyWithin(i, i+ 1)`.
1521+ for ( let i = index ; i < array . length - 1 ; i ++ ) {
1522+ array [ i ] = array [ i + 1 ] ;
1523+ }
1524+ array . pop ( ) ;
1525+ }
1526+
1527+ export function unorderedRemoveItemAt < T > ( array : T [ ] , index : number ) : void {
1528+ // Fill in the "hole" left at `index`.
1529+ array [ index ] = array [ array . length - 1 ] ;
1530+ array . pop ( ) ;
1531+ }
1532+
1533+ /** Remove the *first* occurrence of `item` from the array. */
1534+ export function unorderedRemoveItem < T > ( array : T [ ] , item : T ) : void {
1535+ unorderedRemoveFirstItemWhere ( array , element => element === item ) ;
1536+ }
1537+
1538+ /** Remove the *first* element satisfying `predicate`. */
1539+ function unorderedRemoveFirstItemWhere < T > ( array : T [ ] , predicate : ( element : T ) => boolean ) : void {
1540+ for ( let i = 0 ; i < array . length ; i ++ ) {
1541+ if ( predicate ( array [ i ] ) ) {
1542+ unorderedRemoveItemAt ( array , i ) ;
1543+ break ;
15081544 }
15091545 }
1510- return copiedList ;
15111546 }
15121547
1513- export function createGetCanonicalFileName ( useCaseSensitivefileNames : boolean ) : ( fileName : string ) => string {
1514- return useCaseSensitivefileNames
1548+ export function createGetCanonicalFileName ( useCaseSensitiveFileNames : boolean ) : ( fileName : string ) => string {
1549+ return useCaseSensitiveFileNames
15151550 ? ( ( fileName ) => fileName )
15161551 : ( ( fileName ) => fileName . toLowerCase ( ) ) ;
15171552 }
1518-
15191553}
0 commit comments