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 #11354

Merged
18 commits merged into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 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, string> {
var nameMap = new ts.StringMap<string>();
var nameMap = ts.createMap<string, string>();

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

Expand Down
20 changes: 10 additions & 10 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace ts {
options = opts;
languageVersion = getEmitScriptTarget(options);
inStrictMode = bindInStrictMode(file, opts);
classifiableNames = new StringSet();
classifiableNames = createSet();
symbolCount = 0;
skipTransformFlagAggregation = isDeclarationFile(file);

Expand Down Expand Up @@ -207,11 +207,11 @@ namespace ts {
symbol.declarations.push(node);

if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) {
symbol.exports = new StringMap<Symbol>();
symbol.exports = createMap<string, Symbol>();
}

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

if (symbolFlags & SymbolFlags.Value) {
Expand Down Expand Up @@ -484,7 +484,7 @@ namespace ts {
if (containerFlags & ContainerFlags.IsContainer) {
container = blockScopeContainer = node;
if (containerFlags & ContainerFlags.HasLocals) {
container.locals = new StringMap<Symbol>();
container.locals = createMap<string, Symbol>();
}
addToContainerChain(container);
}
Expand Down Expand Up @@ -1525,7 +1525,7 @@ namespace ts {

const typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral);
typeLiteralSymbol.members = new StringMap([[symbol.name, symbol]]);
typeLiteralSymbol.members = createMap([[symbol.name, symbol]]);
}

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

if (inStrictMode) {
const seen = new StringMap<ElementKind>();
const seen = createMap<string, ElementKind>();

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

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

Expand Down Expand Up @@ -2118,7 +2118,7 @@ namespace ts {
Debug.assert(isInJavaScriptFile(node));
// Declare a 'member' if the container is an ES5 class or ES6 constructor
if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionExpression) {
container.symbol.members = container.symbol.members || new StringMap<Symbol>();
container.symbol.members = container.symbol.members || createMap<string, Symbol>();
// It's acceptable for multiple 'this' assignments of the same identifier to occur
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
}
Expand Down Expand Up @@ -2157,7 +2157,7 @@ namespace ts {

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

// Declare the method/property
Expand Down
72 changes: 36 additions & 36 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ts {
let symbolCount = 0;

const emptyArray: any[] = [];
const emptySymbols = new StringMap<Symbol>();
const emptySymbols = createMap<string, Symbol>();

const compilerOptions = host.getCompilerOptions();
const languageVersion = compilerOptions.target || ScriptTarget.ES3;
Expand Down Expand Up @@ -111,10 +111,10 @@ namespace ts {
};

const tupleTypes: GenericType[] = [];
const unionTypes = new StringMap<UnionType>();
const intersectionTypes = new StringMap<IntersectionType>();
const stringLiteralTypes = new StringMap<LiteralType>();
const numericLiteralTypes = new StringMap<LiteralType>();
const unionTypes = createMap<string, UnionType>();
const intersectionTypes = createMap<string, IntersectionType>();
const stringLiteralTypes = createMap<string, LiteralType>();
const numericLiteralTypes = createMap<string, LiteralType>();
const evolvingArrayTypes: EvolvingArrayType[] = [];

const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown");
Expand All @@ -139,7 +139,7 @@ namespace ts {

const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const emptyGenericType = <GenericType><ObjectType>createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
emptyGenericType.instantiations = new StringMap<TypeReference>();
emptyGenericType.instantiations = createMap<string, TypeReference>();

const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
Expand All @@ -155,7 +155,7 @@ namespace ts {

const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);

const globals = new StringMap<Symbol>();
const globals = createMap<string, Symbol>();
/**
* List of every ambient module with a "*" wildcard.
* Unlike other ambient modules, these can't be stored in `globals` because symbol tables only deal with exact matches.
Expand Down Expand Up @@ -325,7 +325,7 @@ namespace ts {

let jsxElementType: Type;
/** Things we lazy load from the JSX namespace */
const jsxTypes = new StringMap<Type>();
const jsxTypes = createMap<string, Type>();
const JsxNames = {
JSX: "JSX",
IntrinsicElements: "IntrinsicElements",
Expand All @@ -336,11 +336,11 @@ namespace ts {
IntrinsicClassAttributes: "IntrinsicClassAttributes"
};

const subtypeRelation = new StringMap<RelationComparisonResult>();
const assignableRelation = new StringMap<RelationComparisonResult>();
const comparableRelation = new StringMap<RelationComparisonResult>();
const identityRelation = new StringMap<RelationComparisonResult>();
const enumRelation = new StringMap<boolean>();
const subtypeRelation = createMap<string, RelationComparisonResult>();
const assignableRelation = createMap<string, RelationComparisonResult>();
const comparableRelation = createMap<string, RelationComparisonResult>();
const identityRelation = createMap<string, RelationComparisonResult>();
const enumRelation = createMap<string, boolean>();

// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
let _displayBuilder: SymbolDisplayBuilder;
Expand All @@ -354,7 +354,7 @@ namespace ts {
ResolvedReturnType
}

const builtinGlobals = new StringMap([[undefinedSymbol.name, undefinedSymbol]]);
const builtinGlobals = createMap([[undefinedSymbol.name, undefinedSymbol]]);

initializeTypeChecker();

Expand Down Expand Up @@ -437,11 +437,11 @@ namespace ts {
target.declarations.push(node);
});
if (source.members) {
if (!target.members) target.members = new StringMap<Symbol>();
if (!target.members) target.members = createMap<string, Symbol>();
mergeSymbolTable(target.members, source.members);
}
if (source.exports) {
if (!target.exports) target.exports = new StringMap<Symbol>();
if (!target.exports) target.exports = createMap<string, Symbol>();
mergeSymbolTable(target.exports, source.exports);
}
recordMergedSymbol(target, source);
Expand Down Expand Up @@ -1418,7 +1418,7 @@ namespace ts {
// This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
// Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
newSymbol.exports = new StringMap<Symbol>();
newSymbol.exports = createMap<string, Symbol>();
// Cache it so subsequent accesses will return the same module.
globals.set(quotedName, newSymbol);
return newSymbol;
Expand Down Expand Up @@ -1531,8 +1531,8 @@ namespace ts {
// All export * declarations are collected in an __export symbol by the binder
const exportStars = symbol.exports.get("__export");
if (exportStars) {
const nestedSymbols = new StringMap<Symbol>();
const lookupTable = new StringMap<ExportCollisionTracker>();
const nestedSymbols = createMap<string, Symbol>();
const lookupTable = createMap<string, ExportCollisionTracker>();
for (const node of exportStars.declarations) {
const resolvedModule = resolveExternalModuleName(node, (node as ExportDeclaration).moduleSpecifier);
const exportedSymbols = visit(resolvedModule);
Expand Down Expand Up @@ -3237,7 +3237,7 @@ namespace ts {

// Return the type implied by an object binding pattern
function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
const members = new StringMap<Symbol>();
const members = createMap<string, Symbol>();
let hasComputedProperties = false;
forEach(pattern.elements, e => {
const name = e.propertyName || <Identifier>e.name;
Expand Down Expand Up @@ -3842,7 +3842,7 @@ namespace ts {
type.typeParameters = concatenate(outerTypeParameters, localTypeParameters);
type.outerTypeParameters = outerTypeParameters;
type.localTypeParameters = localTypeParameters;
(<GenericType>type).instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
(<GenericType>type).instantiations = createMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
(<GenericType>type).target = <GenericType>type;
(<GenericType>type).typeArguments = type.typeParameters;
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
Expand Down Expand Up @@ -3884,7 +3884,7 @@ namespace ts {
if (typeParameters) {
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
// an instantiation of the type alias with the type parameters supplied as type arguments.
links.instantiations = new StringMap([[getTypeListId(links.typeParameters), type]]);
links.instantiations = createMap([[getTypeListId(links.typeParameters), type]]);
}
}
else {
Expand Down Expand Up @@ -4572,7 +4572,7 @@ namespace ts {
// these partial properties when identifying discriminant properties, but otherwise they are filtered out
// and do not appear to be present in the union type.
function getUnionOrIntersectionProperty(type: UnionOrIntersectionType, name: string): Symbol {
const properties = type.resolvedProperties || (type.resolvedProperties = new StringMap<Symbol>());
const properties = type.resolvedProperties || (type.resolvedProperties = createMap<string, Symbol>());
let property = properties.get(name);
if (!property) {
property = createUnionOrIntersectionProperty(type, name);
Expand Down Expand Up @@ -5393,7 +5393,7 @@ namespace ts {
type.typeParameters = typeParameters;
type.outerTypeParameters = undefined;
type.localTypeParameters = typeParameters;
type.instantiations = new StringMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
type.instantiations = createMap([[getTypeListId(type.typeParameters), <GenericType>type]]);
type.target = <GenericType>type;
type.typeArguments = type.typeParameters;
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
Expand Down Expand Up @@ -6906,7 +6906,7 @@ namespace ts {
}
sourceStack[depth] = source;
targetStack[depth] = target;
maybeStack[depth] = new StringMap([[id, RelationComparisonResult.Succeeded]]);
maybeStack[depth] = createMap([[id, RelationComparisonResult.Succeeded]]);
depth++;
const saveExpandingFlags = expandingFlags;
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth)) expandingFlags |= 1;
Expand Down Expand Up @@ -7591,7 +7591,7 @@ namespace ts {
}

function transformTypeOfMembers(type: Type, f: (propertyType: Type) => Type) {
const members = new StringMap<Symbol>();
const members = createMap<string, Symbol>();
for (const property of getPropertiesOfObjectType(type)) {
const original = getTypeOfSymbol(property);
const updated = f(original);
Expand Down Expand Up @@ -7814,7 +7814,7 @@ namespace ts {
let targetStack: Type[];
let depth = 0;
let inferiority = 0;
const visited = new StringSet();
const visited = createSet();
inferFromTypes(originalSource, originalTarget);

function isInProcess(source: Type, target: Type) {
Expand Down Expand Up @@ -8894,7 +8894,7 @@ namespace ts {
// If we have previously computed the control flow type for the reference at
// this flow loop junction, return the cached type.
const id = getFlowNodeId(flow);
const cache = flowLoopCaches[id] || (flowLoopCaches[id] = new StringMap<Type>());
const cache = flowLoopCaches[id] || (flowLoopCaches[id] = createMap<string, Type>());
if (!key) {
key = getFlowCacheKey(reference);
}
Expand Down Expand Up @@ -10594,7 +10594,7 @@ namespace ts {
// Grammar checking
checkGrammarObjectLiteralExpression(node, inDestructuringPattern);

const propertiesTable = new StringMap<Symbol>();
const propertiesTable = createMap<string, Symbol>();
const propertiesArray: Symbol[] = [];
const contextualType = getApparentTypeOfContextualType(node);
const contextualTypeHasPattern = contextualType && contextualType.pattern &&
Expand Down Expand Up @@ -11145,7 +11145,7 @@ namespace ts {

const targetAttributesType = getJsxElementAttributesType(node);

const nameTable = new StringSet();
const nameTable = createSet();
// Process this array in right-to-left order so we know which
// attributes (mostly from spreads) are being overwritten and
// thus should have their types ignored
Expand Down Expand Up @@ -14622,8 +14622,8 @@ namespace ts {
Property = Getter | Setter
}

const instanceNames = new StringMap<Accessor>();
const staticNames = new StringMap<Accessor>();
const instanceNames = createMap<string, Accessor>();
const staticNames = createMap<string, Accessor>();
for (const member of node.members) {
if (member.kind === SyntaxKind.Constructor) {
for (const param of (member as ConstructorDeclaration).parameters) {
Expand Down Expand Up @@ -14672,7 +14672,7 @@ namespace ts {
}

function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) {
const names = new StringSet();
const names = createSet();
for (const member of node.members) {
if (member.kind == SyntaxKind.PropertySignature) {
let memberName: string;
Expand Down Expand Up @@ -18490,7 +18490,7 @@ namespace ts {
}

function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[] {
const symbols = new StringMap<Symbol>();
const symbols = createMap<string, Symbol>();
let memberFlags: ModifierFlags = ModifierFlags.None;

if (isInsideWithStatementBody(location)) {
Expand Down Expand Up @@ -20315,7 +20315,7 @@ namespace ts {
}

function checkGrammarObjectLiteralExpression(node: ObjectLiteralExpression, inDestructuring: boolean) {
const seen = new StringMap<SymbolFlags>();
const seen = createMap<string, SymbolFlags>();
const Property = 1;
const GetAccessor = 2;
const SetAccessor = 4;
Expand Down Expand Up @@ -20402,7 +20402,7 @@ namespace ts {
}

function checkGrammarJsxElement(node: JsxOpeningLikeElement) {
const seen = new StringSet();
const seen = createSet();
for (const attr of node.attributes) {
if (attr.kind === SyntaxKind.JsxSpreadAttribute) {
continue;
Expand Down
Loading