Skip to content

Commit 06c798a

Browse files
author
Andy Hanson
committed
Use native maps when they're available
1 parent 60ab007 commit 06c798a

Some content is hidden

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

55 files changed

+1364
-885
lines changed

Jakefile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function measure(marker) {
5555
}
5656

5757
var compilerSources = [
58+
"dataStructures.ts",
5859
"core.ts",
5960
"performance.ts",
6061
"sys.ts",
@@ -89,6 +90,7 @@ var compilerSources = [
8990
});
9091

9192
var servicesSources = [
93+
"dataStructures.ts",
9294
"core.ts",
9395
"performance.ts",
9496
"sys.ts",

src/compiler/binder.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace ts {
126126

127127
let symbolCount = 0;
128128
let Symbol: { new (flags: SymbolFlags, name: string): Symbol };
129-
let classifiableNames: Map<string>;
129+
let classifiableNames: Set;
130130

131131
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
132132
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
@@ -140,7 +140,7 @@ namespace ts {
140140
options = opts;
141141
languageVersion = getEmitScriptTarget(options);
142142
inStrictMode = !!file.externalModuleIndicator;
143-
classifiableNames = createMap<string>();
143+
classifiableNames = createSet();
144144
symbolCount = 0;
145145
skipTransformFlagAggregation = isDeclarationFile(file);
146146

@@ -332,17 +332,17 @@ namespace ts {
332332
// Otherwise, we'll be merging into a compatible existing symbol (for example when
333333
// you have multiple 'vars' with the same name in the same container). In this case
334334
// just add this node into the declarations list of the symbol.
335-
symbol = symbolTable[name] || (symbolTable[name] = createSymbol(SymbolFlags.None, name));
335+
symbol = _getOrUpdate(symbolTable, name, name => createSymbol(SymbolFlags.None, name));
336336

337337
if (name && (includes & SymbolFlags.Classifiable)) {
338-
classifiableNames[name] = name;
338+
_add(classifiableNames, name);
339339
}
340340

341341
if (symbol.flags & excludes) {
342342
if (symbol.isReplaceableByMethod) {
343343
// Javascript constructor-declared symbols can be discarded in favor of
344344
// prototype symbols like methods.
345-
symbol = symbolTable[name] = createSymbol(SymbolFlags.None, name);
345+
symbol = _s(symbolTable, name, createSymbol(SymbolFlags.None, name));
346346
}
347347
else {
348348
if (node.name) {
@@ -1444,7 +1444,7 @@ namespace ts {
14441444
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
14451445
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
14461446
typeLiteralSymbol.members = createMap<Symbol>();
1447-
typeLiteralSymbol.members[symbol.name] = symbol;
1447+
_s(typeLiteralSymbol.members, symbol.name, symbol);
14481448
}
14491449

14501450
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
@@ -1475,9 +1475,9 @@ namespace ts {
14751475
? ElementKind.Property
14761476
: ElementKind.Accessor;
14771477

1478-
const existingKind = seen[identifier.text];
1478+
const existingKind = _g(seen, identifier.text);
14791479
if (!existingKind) {
1480-
seen[identifier.text] = currentKind;
1480+
_s(seen, identifier.text, currentKind);
14811481
continue;
14821482
}
14831483

@@ -2049,7 +2049,7 @@ namespace ts {
20492049
constructorFunction.parent = classPrototype;
20502050
classPrototype.parent = leftSideOfAssignment;
20512051

2052-
const funcSymbol = container.locals[constructorFunction.text];
2052+
const funcSymbol = _g(container.locals, constructorFunction.text);
20532053
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
20542054
return;
20552055
}
@@ -2089,7 +2089,7 @@ namespace ts {
20892089
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
20902090
// Add name of class expression into the map for semantic classifier
20912091
if (node.name) {
2092-
classifiableNames[node.name.text] = node.name.text;
2092+
_add(classifiableNames, node.name.text);
20932093
}
20942094
}
20952095

@@ -2105,14 +2105,15 @@ namespace ts {
21052105
// module might have an exported variable called 'prototype'. We can't allow that as
21062106
// that would clash with the built-in 'prototype' for the class.
21072107
const prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype");
2108-
if (symbol.exports[prototypeSymbol.name]) {
2108+
const symbolExport = _g(symbol.exports, prototypeSymbol.name);
2109+
if (symbolExport) {
21092110
if (node.name) {
21102111
node.name.parent = node;
21112112
}
2112-
file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
2113+
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0],
21132114
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
21142115
}
2115-
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
2116+
_s(symbol.exports, prototypeSymbol.name, prototypeSymbol);
21162117
prototypeSymbol.parent = symbol;
21172118
}
21182119

0 commit comments

Comments
 (0)