Skip to content
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

Use native maps where possible #11210

Closed
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function measure(marker) {
}

var compilerSources = [
"dataStructures.ts",
"core.ts",
"performance.ts",
"sys.ts",
Expand Down Expand Up @@ -89,6 +90,7 @@ var compilerSources = [
});

var servicesSources = [
"dataStructures.ts",
"core.ts",
"performance.ts",
"sys.ts",
Expand Down
10 changes: 5 additions & 5 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 Down Expand Up @@ -74,7 +74,7 @@ function buildUniqueNameMap(names: string[]): ts.Map<string> {
var uniqueNames = NameGenerator.ensureUniqueness(names, /* isCaseSensitive */ false, /* isFixed */ undefined);

for (var i = 0; i < names.length; i++) {
nameMap[names[i]] = uniqueNames[i];
ts._s(nameMap, names[i], uniqueNames[i]);
}

return nameMap;
Expand All @@ -91,7 +91,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
for (var i = 0; i < names.length; i++) {
var name = names[i];
var diagnosticDetails = messageTable[name];
var propName = convertPropertyName(nameMap[name]);
var propName = convertPropertyName(ts._g(nameMap, name));

result +=
' ' + propName +
Expand All @@ -114,7 +114,7 @@ function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable,
for (var i = 0; i < names.length; i++) {
var name = names[i];
var diagnosticDetails = messageTable[name];
var propName = convertPropertyName(nameMap[name]);
var propName = convertPropertyName(ts._g(nameMap, name));

result += '\r\n "' + createKey(propName, diagnosticDetails.code) + '"' + ' : "' + name.replace(/[\"]/g, '\\"') + '"';
if (i !== names.length - 1) {
Expand Down
27 changes: 14 additions & 13 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace ts {

let symbolCount = 0;
let Symbol: { new (flags: SymbolFlags, name: string): Symbol };
let classifiableNames: Map<string>;
let classifiableNames: Set;

const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
Expand All @@ -140,7 +140,7 @@ namespace ts {
options = opts;
languageVersion = getEmitScriptTarget(options);
inStrictMode = !!file.externalModuleIndicator;
classifiableNames = createMap<string>();
classifiableNames = createSet();
symbolCount = 0;
skipTransformFlagAggregation = isDeclarationFile(file);

Expand Down Expand Up @@ -332,17 +332,17 @@ 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 = symbolTable[name] || (symbolTable[name] = createSymbol(SymbolFlags.None, name));
symbol = _getOrUpdate(symbolTable, name, name => createSymbol(SymbolFlags.None, name));

if (name && (includes & SymbolFlags.Classifiable)) {
classifiableNames[name] = name;
_add(classifiableNames, name);
}

if (symbol.flags & excludes) {
if (symbol.isReplaceableByMethod) {
// Javascript constructor-declared symbols can be discarded in favor of
// prototype symbols like methods.
symbol = symbolTable[name] = createSymbol(SymbolFlags.None, name);
symbol = _s(symbolTable, name, createSymbol(SymbolFlags.None, name));
}
else {
if (node.name) {
Expand Down Expand Up @@ -1444,7 +1444,7 @@ namespace ts {
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = createMap<Symbol>();
typeLiteralSymbol.members[symbol.name] = symbol;
_s(typeLiteralSymbol.members, symbol.name, symbol);
}

function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
Expand Down Expand Up @@ -1475,9 +1475,9 @@ namespace ts {
? ElementKind.Property
: ElementKind.Accessor;

const existingKind = seen[identifier.text];
const existingKind = _g(seen, identifier.text);
if (!existingKind) {
seen[identifier.text] = currentKind;
_s(seen, identifier.text, currentKind);
continue;
}

Expand Down Expand Up @@ -2049,7 +2049,7 @@ namespace ts {
constructorFunction.parent = classPrototype;
classPrototype.parent = leftSideOfAssignment;

const funcSymbol = container.locals[constructorFunction.text];
const funcSymbol = _g(container.locals, constructorFunction.text);
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
return;
}
Expand Down Expand Up @@ -2089,7 +2089,7 @@ namespace ts {
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
// Add name of class expression into the map for semantic classifier
if (node.name) {
classifiableNames[node.name.text] = node.name.text;
_add(classifiableNames, node.name.text);
}
}

Expand All @@ -2105,14 +2105,15 @@ 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 (symbol.exports[prototypeSymbol.name]) {
const symbolExport = _g(symbol.exports, prototypeSymbol.name);
if (symbolExport) {
if (node.name) {
node.name.parent = node;
}
file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0],
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
_s(symbol.exports, prototypeSymbol.name, prototypeSymbol);
prototypeSymbol.parent = symbol;
}

Expand Down
Loading