Skip to content

Commit

Permalink
Merge pull request #10270 from Microsoft/optimizeMaps
Browse files Browse the repository at this point in the history
Optimize performance of maps
  • Loading branch information
ahejlsberg authored Aug 13, 2016
2 parents d206046 + 87393e0 commit 5bdde3b
Show file tree
Hide file tree
Showing 34 changed files with 324 additions and 337 deletions.
2 changes: 1 addition & 1 deletion scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosti
}

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

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

Expand Down
27 changes: 13 additions & 14 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 = createMap<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 = createMap<Symbol>();
}

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

if (symbolFlags & SymbolFlags.Value) {
Expand Down Expand Up @@ -318,9 +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)
? symbolTable[name]
: (symbolTable[name] = createSymbol(SymbolFlags.None, name));
symbol = symbolTable[name] || (symbolTable[name] = createSymbol(SymbolFlags.None, name));

if (name && (includes & SymbolFlags.Classifiable)) {
classifiableNames[name] = name;
Expand Down Expand Up @@ -434,7 +432,7 @@ namespace ts {
if (containerFlags & ContainerFlags.IsContainer) {
container = blockScopeContainer = node;
if (containerFlags & ContainerFlags.HasLocals) {
container.locals = {};
container.locals = createMap<Symbol>();
}
addToContainerChain(container);
}
Expand Down Expand Up @@ -1399,7 +1397,8 @@ namespace ts {

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

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

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

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

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

Expand Down Expand Up @@ -1977,7 +1976,7 @@ namespace ts {
else {
return;
}
assignee.symbol.members = assignee.symbol.members || {};
assignee.symbol.members = assignee.symbol.members || createMap<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 +2002,7 @@ namespace ts {

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

// Declare the method/property
Expand Down Expand Up @@ -2052,7 +2051,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 (symbol.exports[prototypeSymbol.name]) {
if (node.name) {
node.name.parent = node;
}
Expand Down
Loading

0 comments on commit 5bdde3b

Please sign in to comment.