Skip to content

Optimize performance of maps (with ES3 support) #10298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function main(): void {

var inputFilePath = sys.args[0].replace(/\\/g, "/");
var inputStr = sys.readFile(inputFilePath);

var diagnosticMessages: InputDiagnosticMessageTable = JSON.parse(inputStr);

var names = Utilities.getObjectKeys(diagnosticMessages);
Expand All @@ -44,7 +44,7 @@ function main(): void {
function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosticMessageTable) {
const originalMessageForCode: string[] = [];
let numConflicts = 0;

for (const currentMessage of messages) {
const code = diagnosticTable[currentMessage].code;

Expand All @@ -68,8 +68,8 @@ function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosti
}
}

function buildUniqueNameMap(names: string[]): ts.Map<string> {
var nameMap: ts.Map<string> = {};
function buildUniqueNameMap(names: string[]): ts.MapLike<string> {
var nameMap: ts.MapLike<string> = {};

var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);

Expand All @@ -80,7 +80,7 @@ function buildUniqueNameMap(names: string[]): ts.Map<string> {
return nameMap;
}

function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string>): string {
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.MapLike<string>): string {
var result =
'// <auto-generated />\r\n' +
'/// <reference path="types.ts" />\r\n' +
Expand All @@ -107,7 +107,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
return result;
}

function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string>): string {
function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.MapLike<string>): string {
var result =
'{';
var names = Utilities.getObjectKeys(messageTable);
Expand Down
24 changes: 12 additions & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace ts {
options = opts;
languageVersion = getEmitScriptTarget(options);
inStrictMode = !!file.externalModuleIndicator;
classifiableNames = {};
classifiableNames = Map.create<string>();
symbolCount = 0;

Symbol = objectAllocator.getSymbolConstructor();
Expand Down Expand Up @@ -183,11 +183,11 @@ namespace ts {
symbol.declarations.push(node);

if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) {
symbol.exports = {};
symbol.exports = Map.create<Symbol>();
}

if (symbolFlags & SymbolFlags.HasMembers && !symbol.members) {
symbol.members = {};
symbol.members = Map.create<Symbol>();
}

if (symbolFlags & SymbolFlags.Value) {
Expand Down Expand Up @@ -318,7 +318,7 @@ namespace ts {
// Otherwise, we'll be merging into a compatible existing symbol (for example when
// you have multiple 'vars' with the same name in the same container). In this case
// just add this node into the declarations list of the symbol.
symbol = hasProperty(symbolTable, name)
symbol = Map.has(symbolTable, name)
? symbolTable[name]
: (symbolTable[name] = createSymbol(SymbolFlags.None, name));

Expand Down Expand Up @@ -434,7 +434,7 @@ namespace ts {
if (containerFlags & ContainerFlags.IsContainer) {
container = blockScopeContainer = node;
if (containerFlags & ContainerFlags.HasLocals) {
container.locals = {};
container.locals = Map.create<Symbol>();
}
addToContainerChain(container);
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ namespace ts {

const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = { [symbol.name]: symbol };
typeLiteralSymbol.members = Map.create<Symbol>({ [symbol.name]: symbol });
}

function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
Expand All @@ -1409,7 +1409,7 @@ namespace ts {
}

if (inStrictMode) {
const seen: Map<ElementKind> = {};
const seen = Map.create<ElementKind>();

for (const prop of node.properties) {
if (prop.name.kind !== SyntaxKind.Identifier) {
Expand Down Expand Up @@ -1465,7 +1465,7 @@ namespace ts {
// fall through.
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = {};
blockScopeContainer.locals = Map.create<Symbol>();
addToContainerChain(blockScopeContainer);
}
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
Expand Down Expand Up @@ -1924,7 +1924,7 @@ namespace ts {
}
}

file.symbol.globalExports = file.symbol.globalExports || {};
file.symbol.globalExports = file.symbol.globalExports || Map.create<Symbol>();
declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
}

Expand Down Expand Up @@ -1977,7 +1977,7 @@ namespace ts {
else {
return;
}
assignee.symbol.members = assignee.symbol.members || {};
assignee.symbol.members = assignee.symbol.members || Map.create<Symbol>();
// It's acceptable for multiple 'this' assignments of the same identifier to occur
declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
}
Expand All @@ -2003,7 +2003,7 @@ namespace ts {

// Set up the members collection if it doesn't exist already
if (!funcSymbol.members) {
funcSymbol.members = {};
funcSymbol.members = Map.create<Symbol>();
}

// Declare the method/property
Expand Down Expand Up @@ -2052,7 +2052,7 @@ namespace ts {
// module might have an exported variable called 'prototype'. We can't allow that as
// that would clash with the built-in 'prototype' for the class.
const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
if (hasProperty(symbol.exports, prototypeSymbol.name)) {
if (Map.has(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
Expand Down
Loading