Replace SparseArray<T> with T[]

This commit is contained in:
Andy Hanson 2016-12-28 09:39:58 -08:00
parent 346a86582b
commit 2e6f369e8f
12 changed files with 23 additions and 30 deletions

View File

@ -4084,7 +4084,7 @@ namespace ts {
enumType.symbol = symbol;
if (enumHasLiteralMembers(symbol)) {
const memberTypeList: Type[] = [];
const memberTypes: SparseArray<EnumLiteralType> = [];
const memberTypes: EnumLiteralType[] = [];
for (const declaration of enumType.symbol.declarations) {
if (declaration.kind === SyntaxKind.EnumDeclaration) {
computeEnumMemberValues(<EnumDeclaration>declaration);

View File

@ -2646,7 +2646,7 @@ namespace ts {
return destEmitNode;
}
function mergeTokenSourceMapRanges(sourceRanges: SparseArray<TextRange>, destRanges: SparseArray<TextRange>) {
function mergeTokenSourceMapRanges(sourceRanges: TextRange[], destRanges: TextRange[]) {
if (!destRanges) destRanges = [];
for (const key in sourceRanges) {
destRanges[key] = sourceRanges[key];
@ -3277,7 +3277,7 @@ namespace ts {
externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; // imports of other external modules
externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers
exportSpecifiers: Map<ExportSpecifier[]>; // export specifiers by name
exportedBindings: SparseArray<Identifier[]>; // exported names of local declarations
exportedBindings: Identifier[][]; // exported names of local declarations
exportedNames: Identifier[]; // all exported names local to module
exportEquals: ExportAssignment | undefined; // an export= declaration if one was present
hasExportStarsToExportValues: boolean; // whether this module contains export*
@ -3286,7 +3286,7 @@ namespace ts {
export function collectExternalModuleInfo(sourceFile: SourceFile, resolver: EmitResolver, compilerOptions: CompilerOptions): ExternalModuleInfo {
const externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[] = [];
const exportSpecifiers = createMultiMap<ExportSpecifier>();
const exportedBindings: SparseArray<Identifier[]> = [];
const exportedBindings: Identifier[][] = [];
const uniqueExports = createMap<boolean>();
let exportedNames: Identifier[];
let hasExportDefault = false;
@ -3435,7 +3435,7 @@ namespace ts {
}
/** Use a sparse array as a multi-map. */
function multiMapSparseArrayAdd<V>(map: SparseArray<V[]>, key: number, value: V): V[] {
function multiMapSparseArrayAdd<V>(map: V[][], key: number, value: V): V[] {
let values = map[key];
if (values) {
values.push(value);

View File

@ -243,7 +243,7 @@ namespace ts {
let currentSourceFile: SourceFile;
let renamedCatchVariables: Map<boolean>;
let renamedCatchVariableDeclarations: SparseArray<Identifier>;
let renamedCatchVariableDeclarations: Identifier[];
let inGeneratorFunctionBody: boolean;
let inStatementContainingYield: boolean;

View File

@ -39,12 +39,12 @@ namespace ts {
context.enableSubstitution(SyntaxKind.ShorthandPropertyAssignment); // Substitutes shorthand property assignments for imported/exported symbols.
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
const moduleInfoMap: ExternalModuleInfo[] = []; // The ExternalModuleInfo for each file.
const deferredExports: Statement[][] = []; // Exports to defer until an EndOfDeclarationMarker is found.
let currentSourceFile: SourceFile; // The current file.
let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file.
let noSubstitution: SparseArray<boolean>; // Set of nodes for which substitution rules should be ignored.
let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored.
return transformSourceFile;

View File

@ -28,10 +28,10 @@ namespace ts {
context.enableSubstitution(SyntaxKind.PostfixUnaryExpression); // Substitutes updates to exported symbols.
context.enableEmitNotification(SyntaxKind.SourceFile); // Restore state when substituting nodes in a file.
const moduleInfoMap: SparseArray<ExternalModuleInfo> = []; // The ExternalModuleInfo for each file.
const deferredExports: SparseArray<Statement[]> = []; // Exports to defer until an EndOfDeclarationMarker is found.
const exportFunctionsMap: SparseArray<Identifier> = []; // The export function associated with a source file.
const noSubstitutionMap: SparseArray<SparseArray<boolean>> = []; // Set of nodes for which substitution rules should be ignored for each file.
const moduleInfoMap: ExternalModuleInfo[] = []; // The ExternalModuleInfo for each file.
const deferredExports: Statement[][] = []; // Exports to defer until an EndOfDeclarationMarker is found.
const exportFunctionsMap: Identifier[] = []; // The export function associated with a source file.
const noSubstitutionMap: boolean[][] = []; // Set of nodes for which substitution rules should be ignored for each file.
let currentSourceFile: SourceFile; // The current file.
let moduleInfo: ExternalModuleInfo; // ExternalModuleInfo for the current file.
@ -39,7 +39,7 @@ namespace ts {
let contextObject: Identifier; // The context object for the current file.
let hoistedStatements: Statement[];
let enclosingBlockScopedContainer: Node;
let noSubstitution: SparseArray<boolean>; // Set of nodes for which substitution rules should be ignored.
let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored.
return transformSourceFile;

View File

@ -60,7 +60,7 @@ namespace ts {
* A map that keeps track of aliases created for classes with decorators to avoid issues
* with the double-binding behavior of classes.
*/
let classAliases: SparseArray<Identifier>;
let classAliases: Identifier[];
/**
* Keeps track of whether we are within any containing namespaces when performing

View File

@ -8,13 +8,6 @@
[index: string]: T;
}
/**
* Like MapLike, but keys must be numbers.
*/
export interface SparseArray<T> {
[key: number]: T;
}
/** ES6 Map interface. */
export interface Map<T> {
get(key: string): T;
@ -2854,7 +2847,7 @@
// Enum types (TypeFlags.Enum)
export interface EnumType extends Type {
memberTypes: SparseArray<EnumLiteralType>;
memberTypes: EnumLiteralType[];
}
// Enum types (TypeFlags.EnumLiteral)
@ -3684,7 +3677,7 @@
flags?: EmitFlags; // Flags that customize emit
commentRange?: TextRange; // The text range to use when emitting leading or trailing comments
sourceMapRange?: TextRange; // The text range to use when emitting leading or trailing source mappings
tokenSourceMapRanges?: SparseArray<TextRange>; // The text range to use when emitting source mappings for tokens
tokenSourceMapRanges?: TextRange[]; // The text range to use when emitting source mappings for tokens
constantValue?: number; // The constant value of an expression
externalHelpersModuleName?: Identifier; // The local name for an imported helpers module
helpers?: EmitHelper[]; // Emit helpers for the node

View File

@ -3362,7 +3362,7 @@ namespace ts {
return false;
}
const syntaxKindCache: SparseArray<string> = [];
const syntaxKindCache: string[] = [];
export function formatSyntaxKind(kind: SyntaxKind): string {
const syntaxKindEnum = (<any>ts).SyntaxKind;

View File

@ -416,7 +416,7 @@ namespace ts.server {
class InProcClient {
private server: InProcSession;
private seq = 0;
private callbacks: SparseArray<(resp: protocol.Response) => void> = [];
private callbacks: Array<(resp: protocol.Response) => void> = [];
private eventHandlers = createMap<(args: any) => void>();
handle(msg: protocol.Message): void {

View File

@ -292,7 +292,7 @@ namespace ts.projectSystem {
}
export class Callbacks {
private map: SparseArray<TimeOutCallback> = [];
private map: TimeOutCallback[] = [];
private nextId = 1;
register(cb: (...args: any[]) => void, args: any[]) {

View File

@ -16,7 +16,7 @@ namespace ts {
}
export namespace codefix {
const codeFixes: SparseArray<CodeFix[]> = [];
const codeFixes: CodeFix[][] = [];
export function registerCodeFix(action: CodeFix) {
forEach(action.errorCodes, error => {

View File

@ -14,7 +14,7 @@ namespace ts.codefix {
}
class ImportCodeActionMap {
private symbolIdToActionMap: SparseArray<ImportCodeAction[]> = [];
private symbolIdToActionMap: ImportCodeAction[][] = [];
addAction(symbolId: number, newAction: ImportCodeAction) {
if (!newAction) {
@ -125,7 +125,7 @@ namespace ts.codefix {
const symbolIdActionMap = new ImportCodeActionMap();
// this is a module id -> module import declaration map
const cachedImportDeclarations: SparseArray<(ImportDeclaration | ImportEqualsDeclaration)[]> = [];
const cachedImportDeclarations: (ImportDeclaration | ImportEqualsDeclaration)[][] = [];
let cachedNewImportInsertPosition: number;
const allPotentialModules = checker.getAmbientModules();