Skip to content

Commit 2e6f369

Browse files
author
Andy Hanson
committed
Replace SparseArray<T> with T[]
1 parent 346a865 commit 2e6f369

File tree

12 files changed

+23
-30
lines changed

12 files changed

+23
-30
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4084,7 +4084,7 @@ namespace ts {
40844084
enumType.symbol = symbol;
40854085
if (enumHasLiteralMembers(symbol)) {
40864086
const memberTypeList: Type[] = [];
4087-
const memberTypes: SparseArray<EnumLiteralType> = [];
4087+
const memberTypes: EnumLiteralType[] = [];
40884088
for (const declaration of enumType.symbol.declarations) {
40894089
if (declaration.kind === SyntaxKind.EnumDeclaration) {
40904090
computeEnumMemberValues(<EnumDeclaration>declaration);

src/compiler/factory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@ namespace ts {
26462646
return destEmitNode;
26472647
}
26482648

2649-
function mergeTokenSourceMapRanges(sourceRanges: SparseArray<TextRange>, destRanges: SparseArray<TextRange>) {
2649+
function mergeTokenSourceMapRanges(sourceRanges: TextRange[], destRanges: TextRange[]) {
26502650
if (!destRanges) destRanges = [];
26512651
for (const key in sourceRanges) {
26522652
destRanges[key] = sourceRanges[key];
@@ -3277,7 +3277,7 @@ namespace ts {
32773277
externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules
32783278
externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers
32793279
exportSpecifiers: Map<ExportSpecifier[]>; // export specifiers by name
3280-
exportedBindings: SparseArray<Identifier[]>; // exported names of local declarations
3280+
exportedBindings: Identifier[][]; // exported names of local declarations
32813281
exportedNames: Identifier[]; // all exported names local to module
32823282
exportEquals: ExportAssignment | undefined; // an export= declaration if one was present
32833283
hasExportStarsToExportValues: boolean; // whether this module contains export*
@@ -3286,7 +3286,7 @@ namespace ts {
32863286
export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
32873287
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
32883288
const exportSpecifiers = createMultiMap<ExportSpecifier>();
3289-
const exportedBindings: SparseArray<Identifier[]> = [];
3289+
const exportedBindings: Identifier[][] = [];
32903290
const uniqueExports = createMap<boolean>();
32913291
let exportedNames: Identifier[];
32923292
let hasExportDefault = false;
@@ -3435,7 +3435,7 @@ namespace ts {
34353435
}
34363436

34373437
/** Use a sparse array as a multi-map. */
3438-
function multiMapSparseArrayAdd<V>(map: SparseArray<V[]>, key: number, value: V): V[] {
3438+
function multiMapSparseArrayAdd<V>(map: V[][], key: number, value: V): V[] {
34393439
let values = map[key];
34403440
if (values) {
34413441
values.push(value);

src/compiler/transformers/generators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace ts {
243243

244244
let currentSourceFile: SourceFile;
245245
let renamedCatchVariables: Map<boolean>;
246-
let renamedCatchVariableDeclarations: SparseArray<Identifier>;
246+
let renamedCatchVariableDeclarations: Identifier[];
247247

248248
let inGeneratorFunctionBody: boolean;
249249
let inStatementContainingYield: boolean;

src/compiler/transformers/module/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ namespace ts {
3939
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
4040
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
4141

42-
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
43-
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
42+
const moduleInfoMap: ExternalModuleInfo[] = []; // The ExternalModuleInfo for each file.
43+
const deferredExports: Statement[][] = []; // Exports to defer until an EndOfDeclarationMarker is found.
4444

4545
let currentSourceFile: SourceFile; // The current file.
4646
let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file.
47-
let noSubstitution: SparseArray<boolean>; // Set of nodes for which substitution rules should be ignored.
47+
let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored.
4848

4949
return transformSourceFile;
5050

src/compiler/transformers/module/system.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ namespace ts {
2828
context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); // Substitutes updates to exported symbols.
2929
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
3030

31-
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
32-
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
33-
const exportFunctionsMap: SparseArray<Identifier> = []; // The export function associated with a source file.
34-
const noSubstitutionMap: SparseArray<SparseArray<boolean>> = []; // Set of nodes for which substitution rules should be ignored for each file.
31+
const moduleInfoMap: ExternalModuleInfo[] = []; // The ExternalModuleInfo for each file.
32+
const deferredExports: Statement[][] = []; // Exports to defer until an EndOfDeclarationMarker is found.
33+
const exportFunctionsMap: Identifier[] = []; // The export function associated with a source file.
34+
const noSubstitutionMap: boolean[][] = []; // Set of nodes for which substitution rules should be ignored for each file.
3535

3636
let currentSourceFile: SourceFile; // The current file.
3737
let moduleInfo: ExternalModuleInfo; // ExternalModuleInfo for the current file.
3838
let exportFunction: Identifier; // The export function for the current file.
3939
let contextObject: Identifier; // The context object for the current file.
4040
let hoistedStatements: Statement[];
4141
let enclosingBlockScopedContainer: Node;
42-
let noSubstitution: SparseArray<boolean>; // Set of nodes for which substitution rules should be ignored.
42+
let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored.
4343

4444
return transformSourceFile;
4545

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ts {
6060
* A map that keeps track of aliases created for classes with decorators to avoid issues
6161
* with the double-binding behavior of classes.
6262
*/
63-
let classAliases: SparseArray<Identifier>;
63+
let classAliases: Identifier[];
6464

6565
/**
6666
* Keeps track of whether we are within any containing namespaces when performing

src/compiler/types.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
[index: string]: T;
99
}
1010

11-
/**
12-
* Like MapLike, but keys must be numbers.
13-
*/
14-
export interface SparseArray<T> {
15-
[key: number]: T;
16-
}
17-
1811
/** ES6 Map interface. */
1912
export interface Map<T> {
2013
get(key: string): T;
@@ -2854,7 +2847,7 @@
28542847

28552848
// Enum types (TypeFlags.Enum)
28562849
export interface EnumType extends Type {
2857-
memberTypes: SparseArray<EnumLiteralType>;
2850+
memberTypes: EnumLiteralType[];
28582851
}
28592852

28602853
// Enum types (TypeFlags.EnumLiteral)
@@ -3684,7 +3677,7 @@
36843677
flags?: EmitFlags; // Flags that customize emit
36853678
commentRange?: TextRange; // The text range to use when emitting leading or trailing comments
36863679
sourceMapRange?: TextRange; // The text range to use when emitting leading or trailing source mappings
3687-
tokenSourceMapRanges?: SparseArray<TextRange>; // The text range to use when emitting source mappings for tokens
3680+
tokenSourceMapRanges?: TextRange[]; // The text range to use when emitting source mappings for tokens
36883681
constantValue?: number; // The constant value of an expression
36893682
externalHelpersModuleName?: Identifier; // The local name for an imported helpers module
36903683
helpers?: EmitHelper[]; // Emit helpers for the node

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ namespace ts {
33623362
return false;
33633363
}
33643364

3365-
const syntaxKindCache: SparseArray<string> = [];
3365+
const syntaxKindCache: string[] = [];
33663366

33673367
export function formatSyntaxKind(kind: SyntaxKind): string {
33683368
const syntaxKindEnum = (<any>ts).SyntaxKind;

src/harness/unittests/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ namespace ts.server {
416416
class InProcClient {
417417
private server: InProcSession;
418418
private seq = 0;
419-
private callbacks: SparseArray<(resp: protocol.Response) => void> = [];
419+
private callbacks: Array<(resp: protocol.Response) => void> = [];
420420
private eventHandlers = createMap<(args: any) => void>();
421421

422422
handle(msg: protocol.Message): void {

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ namespace ts.projectSystem {
292292
}
293293

294294
export class Callbacks {
295-
private map: SparseArray<TimeOutCallback> = [];
295+
private map: TimeOutCallback[] = [];
296296
private nextId = 1;
297297

298298
register(cb: (...args: any[]) => void, args: any[]) {

src/services/codefixes/codeFixProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ts {
1616
}
1717

1818
export namespace codefix {
19-
const codeFixes: SparseArray<CodeFix[]> = [];
19+
const codeFixes: CodeFix[][] = [];
2020

2121
export function registerCodeFix(action: CodeFix) {
2222
forEach(action.errorCodes, error => {

src/services/codefixes/importFixes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ts.codefix {
1414
}
1515

1616
class ImportCodeActionMap {
17-
private symbolIdToActionMap: SparseArray<ImportCodeAction[]> = [];
17+
private symbolIdToActionMap: ImportCodeAction[][] = [];
1818

1919
addAction(symbolId: number, newAction: ImportCodeAction) {
2020
if (!newAction) {
@@ -125,7 +125,7 @@ namespace ts.codefix {
125125
const symbolIdActionMap = new ImportCodeActionMap();
126126

127127
// this is a module id -> module import declaration map
128-
const cachedImportDeclarations: SparseArray<(ImportDeclaration | ImportEqualsDeclaration)[]> = [];
128+
const cachedImportDeclarations: (ImportDeclaration | ImportEqualsDeclaration)[][] = [];
129129
let cachedNewImportInsertPosition: number;
130130

131131
const allPotentialModules = checker.getAmbientModules();

0 commit comments

Comments
 (0)