Skip to content

Commit adfdae0

Browse files
author
Andy
authored
Merge pull request #11354 from Microsoft/map4
Use native maps when they're available
2 parents aad663c + bcc0807 commit adfdae0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1781
-1430
lines changed

Jakefile.js

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function measure(marker) {
5757
}
5858

5959
var compilerSources = [
60+
"collections.ts",
6061
"core.ts",
6162
"performance.ts",
6263
"sys.ts",
@@ -93,6 +94,7 @@ var compilerSources = [
9394
});
9495

9596
var servicesSources = [
97+
"collections.ts",
9698
"core.ts",
9799
"performance.ts",
98100
"sys.ts",

scripts/processDiagnosticMessages.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function main(): void {
2727

2828
var inputFilePath = sys.args[0].replace(/\\/g, "/");
2929
var inputStr = sys.readFile(inputFilePath);
30-
30+
3131
var diagnosticMessages: InputDiagnosticMessageTable = JSON.parse(inputStr);
3232

3333
var names = Utilities.getObjectKeys(diagnosticMessages);
@@ -44,7 +44,7 @@ function main(): void {
4444
function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosticMessageTable) {
4545
const originalMessageForCode: string[] = [];
4646
let numConflicts = 0;
47-
47+
4848
for (const currentMessage of messages) {
4949
const code = diagnosticTable[currentMessage].code;
5050

@@ -68,19 +68,19 @@ function checkForUniqueCodes(messages: string[], diagnosticTable: InputDiagnosti
6868
}
6969
}
7070

71-
function buildUniqueNameMap(names: string[]): ts.Map<string> {
72-
var nameMap = ts.createMap<string>();
71+
function buildUniqueNameMap(names: string[]): ts.Map<string, string> {
72+
var nameMap = ts.createMap<string, string>();
7373

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

7676
for (var i = 0; i < names.length; i++) {
77-
nameMap[names[i]] = uniqueNames[i];
77+
nameMap.set(names[i], uniqueNames[i]);
7878
}
7979

8080
return nameMap;
8181
}
8282

83-
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string>): string {
83+
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string, string>): string {
8484
var result =
8585
'// <auto-generated />\r\n' +
8686
'/// <reference path="types.ts" />\r\n' +
@@ -91,7 +91,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
9191
for (var i = 0; i < names.length; i++) {
9292
var name = names[i];
9393
var diagnosticDetails = messageTable[name];
94-
var propName = convertPropertyName(nameMap[name]);
94+
var propName = convertPropertyName(nameMap.get(name));
9595

9696
result +=
9797
' ' + propName +
@@ -107,14 +107,14 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
107107
return result;
108108
}
109109

110-
function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string>): string {
110+
function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable, nameMap: ts.Map<string, string>): string {
111111
var result =
112112
'{';
113113
var names = Utilities.getObjectKeys(messageTable);
114114
for (var i = 0; i < names.length; i++) {
115115
var name = names[i];
116116
var diagnosticDetails = messageTable[name];
117-
var propName = convertPropertyName(nameMap[name]);
117+
var propName = convertPropertyName(nameMap.get(name));
118118

119119
result += '\r\n "' + createKey(propName, diagnosticDetails.code) + '"' + ' : "' + name.replace(/[\"]/g, '\\"') + '"';
120120
if (i !== names.length - 1) {

src/compiler/binder.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace ts {
133133

134134
let symbolCount = 0;
135135
let Symbol: { new (flags: SymbolFlags, name: string): Symbol };
136-
let classifiableNames: Map<string>;
136+
let classifiableNames: Set<string>;
137137

138138
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
139139
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
@@ -147,7 +147,7 @@ namespace ts {
147147
options = opts;
148148
languageVersion = getEmitScriptTarget(options);
149149
inStrictMode = bindInStrictMode(file, opts);
150-
classifiableNames = createMap<string>();
150+
classifiableNames = createSet();
151151
symbolCount = 0;
152152
skipTransformFlagAggregation = isDeclarationFile(file);
153153

@@ -207,11 +207,11 @@ namespace ts {
207207
symbol.declarations.push(node);
208208

209209
if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) {
210-
symbol.exports = createMap<Symbol>();
210+
symbol.exports = createMap<string, Symbol>();
211211
}
212212

213213
if (symbolFlags & SymbolFlags.HasMembers && !symbol.members) {
214-
symbol.members = createMap<Symbol>();
214+
symbol.members = createMap<string, Symbol>();
215215
}
216216

217217
if (symbolFlags & SymbolFlags.Value) {
@@ -349,17 +349,17 @@ namespace ts {
349349
// Otherwise, we'll be merging into a compatible existing symbol (for example when
350350
// you have multiple 'vars' with the same name in the same container). In this case
351351
// just add this node into the declarations list of the symbol.
352-
symbol = symbolTable[name] || (symbolTable[name] = createSymbol(SymbolFlags.None, name));
352+
symbol = getOrUpdate(symbolTable, name, name => createSymbol(SymbolFlags.None, name));
353353

354354
if (name && (includes & SymbolFlags.Classifiable)) {
355-
classifiableNames[name] = name;
355+
classifiableNames.add(name);
356356
}
357357

358358
if (symbol.flags & excludes) {
359359
if (symbol.isReplaceableByMethod) {
360360
// Javascript constructor-declared symbols can be discarded in favor of
361361
// prototype symbols like methods.
362-
symbol = symbolTable[name] = createSymbol(SymbolFlags.None, name);
362+
symbol = setAndReturn(symbolTable, name, createSymbol(SymbolFlags.None, name));
363363
}
364364
else {
365365
if (node.name) {
@@ -484,7 +484,7 @@ namespace ts {
484484
if (containerFlags & ContainerFlags.IsContainer) {
485485
container = blockScopeContainer = node;
486486
if (containerFlags & ContainerFlags.HasLocals) {
487-
container.locals = createMap<Symbol>();
487+
container.locals = createMap<string, Symbol>();
488488
}
489489
addToContainerChain(container);
490490
}
@@ -1525,8 +1525,7 @@ namespace ts {
15251525

15261526
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
15271527
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
1528-
typeLiteralSymbol.members = createMap<Symbol>();
1529-
typeLiteralSymbol.members[symbol.name] = symbol;
1528+
typeLiteralSymbol.members = createMap([[symbol.name, symbol]]);
15301529
}
15311530

15321531
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
@@ -1536,7 +1535,7 @@ namespace ts {
15361535
}
15371536

15381537
if (inStrictMode) {
1539-
const seen = createMap<ElementKind>();
1538+
const seen = createMap<string, ElementKind>();
15401539

15411540
for (const prop of node.properties) {
15421541
if (prop.name.kind !== SyntaxKind.Identifier) {
@@ -1557,9 +1556,9 @@ namespace ts {
15571556
? ElementKind.Property
15581557
: ElementKind.Accessor;
15591558

1560-
const existingKind = seen[identifier.text];
1559+
const existingKind = seen.get(identifier.text);
15611560
if (!existingKind) {
1562-
seen[identifier.text] = currentKind;
1561+
seen.set(identifier.text, currentKind);
15631562
continue;
15641563
}
15651564

@@ -1592,7 +1591,7 @@ namespace ts {
15921591
// fall through.
15931592
default:
15941593
if (!blockScopeContainer.locals) {
1595-
blockScopeContainer.locals = createMap<Symbol>();
1594+
blockScopeContainer.locals = createMap<string, Symbol>();
15961595
addToContainerChain(blockScopeContainer);
15971596
}
15981597
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
@@ -2072,7 +2071,7 @@ namespace ts {
20722071
}
20732072
}
20742073

2075-
file.symbol.globalExports = file.symbol.globalExports || createMap<Symbol>();
2074+
file.symbol.globalExports = file.symbol.globalExports || createMap<string, Symbol>();
20762075
declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
20772076
}
20782077

@@ -2119,7 +2118,7 @@ namespace ts {
21192118
Debug.assert(isInJavaScriptFile(node));
21202119
// Declare a 'member' if the container is an ES5 class or ES6 constructor
21212120
if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionExpression) {
2122-
container.symbol.members = container.symbol.members || createMap<Symbol>();
2121+
container.symbol.members = container.symbol.members || createMap<string, Symbol>();
21232122
// It's acceptable for multiple 'this' assignments of the same identifier to occur
21242123
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
21252124
}
@@ -2151,14 +2150,14 @@ namespace ts {
21512150
constructorFunction.parent = classPrototype;
21522151
classPrototype.parent = leftSideOfAssignment;
21532152

2154-
const funcSymbol = container.locals[constructorFunction.text];
2153+
const funcSymbol = container.locals.get(constructorFunction.text);
21552154
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
21562155
return;
21572156
}
21582157

21592158
// Set up the members collection if it doesn't exist already
21602159
if (!funcSymbol.members) {
2161-
funcSymbol.members = createMap<Symbol>();
2160+
funcSymbol.members = createMap<string, Symbol>();
21622161
}
21632162

21642163
// Declare the method/property
@@ -2191,7 +2190,7 @@ namespace ts {
21912190
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
21922191
// Add name of class expression into the map for semantic classifier
21932192
if (node.name) {
2194-
classifiableNames[node.name.text] = node.name.text;
2193+
classifiableNames.add(node.name.text);
21952194
}
21962195
}
21972196

@@ -2207,14 +2206,15 @@ namespace ts {
22072206
// module might have an exported variable called 'prototype'. We can't allow that as
22082207
// that would clash with the built-in 'prototype' for the class.
22092208
const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
2210-
if (symbol.exports[prototypeSymbol.name]) {
2209+
const symbolExport = symbol.exports.get(prototypeSymbol.name);
2210+
if (symbolExport) {
22112211
if (node.name) {
22122212
node.name.parent = node;
22132213
}
2214-
file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
2214+
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0],
22152215
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
22162216
}
2217-
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
2217+
symbol.exports.set(prototypeSymbol.name, prototypeSymbol);
22182218
prototypeSymbol.parent = symbol;
22192219
}
22202220

0 commit comments

Comments
 (0)