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 when they're available #12715

Merged
30 commits merged into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6b1cc89
Use native maps when they're available
Dec 5, 2016
b15ffda
Simplify forEachKeyInMap and someKeyInMap
Dec 8, 2016
863e4d6
Clean up helpers
Dec 8, 2016
8121de7
Fix target error for gulp
Dec 8, 2016
8dbb8e7
Add comment
Dec 8, 2016
55fc62b
Merge branch 'master' into map5
Dec 12, 2016
5c304d0
Remove `createObject`; use `Object.create` directly.
Dec 12, 2016
b53b5cf
Remove the "set" function and use `map.set` with multiple lines of co…
Dec 12, 2016
8386d49
Use sparse arrays for number-keyed maps
Dec 27, 2016
5555258
Add iterators to Map interface, and shim iterators
Dec 27, 2016
3d7b5e6
Make `createMapLike` private and rename to `createDictionaryObject`
Dec 27, 2016
9e33585
Merge branch 'master' into map5
Dec 27, 2016
f510897
Remove "sparseArray" constructor function and just use array literals
Dec 28, 2016
39c19a7
Inline `keysOfMap` and `valuesOfMap`.
Dec 28, 2016
932eaa3
Rename and consolidate map iteration helpers
Dec 28, 2016
145f0b2
Add `createMultiMap` to replace `multiMapAdd` and `multiMapRemove`
Dec 28, 2016
346a865
Merge branch 'master' into map5
Dec 28, 2016
2e6f369
Replace SparseArray<T> with T[]
Dec 28, 2016
a677712
Merge branch 'master' into map5
Dec 29, 2016
8c5afd7
Merge branch 'master' into map5
Jan 6, 2017
9221336
Fix name: `mapEntries` is more accurate
Jan 6, 2017
c28d98a
Fix test
Jan 9, 2017
a0641b2
Merge branch 'master' into map5
Jan 9, 2017
f0e1fd9
Merge branch 'master' into map5
Jan 11, 2017
37e18d9
Add `createMapFromTemplate` helper
Jan 11, 2017
30462e1
Merge branch 'master' into map5
Jan 11, 2017
b98e82e
Fix one more use of `createMapFromTemplate`
Jan 12, 2017
113338c
Merge branch 'master' into map5
Jan 12, 2017
6b6c34b
Fix typo
Jan 12, 2017
30ccc7a
Merge branch 'master' into map5
Jan 17, 2017
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
1 change: 1 addition & 0 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ const builtGeneratedDiagnosticMessagesJSON = path.join(builtLocalDirectory, "dia
// processDiagnosticMessages script
gulp.task(processDiagnosticMessagesJs, false, [], () => {
const settings: tsc.Settings = getCompilerSettings({
target: "es5",
declaration: false,
removeComments: true,
noResolve: false,
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];
nameMap.set(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(nameMap.get(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(nameMap.get(name));

result += '\r\n "' + createKey(propName, diagnosticDetails.code) + '"' + ' : "' + name.replace(/[\"]/g, '\\"') + '"';
if (i !== names.length - 1) {
Expand Down
24 changes: 12 additions & 12 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,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 = symbolTable.get(name) || set(symbolTable, name, createSymbol(SymbolFlags.None, name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be on one line. I'd rather see this as multiple lines and ditch the set function.


if (name && (includes & SymbolFlags.Classifiable)) {
classifiableNames[name] = name;
classifiableNames.set(name, 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 = set(symbolTable, name, createSymbol(SymbolFlags.None, name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name)); and we remove one more usage of the set function.

}
else {
if (node.name) {
Expand Down Expand Up @@ -1570,7 +1570,7 @@ namespace ts {
const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = createMap<Symbol>();
typeLiteralSymbol.members[symbol.name] = symbol;
typeLiteralSymbol.members.set(symbol.name, symbol);
}

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

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

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

const funcSymbol = container.locals[constructorFunction.text];
const funcSymbol = container.locals.get(constructorFunction.text);
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) {
return;
}
Expand Down Expand Up @@ -2239,7 +2239,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;
classifiableNames.set(node.name.text, node.name.text);
}
}

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

Expand Down
Loading