mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Add constructor functions for {Symbol,Node}Links (#36845)
Using a constructor function like this can help node better optimize object allocation. This improves memory usage when compiling `src/compiler` from **277M** to **270M**, a nice ~3% win.
This commit is contained in:
@@ -242,6 +242,13 @@ namespace ts {
|
||||
ExportNamespace = 1 << 2,
|
||||
}
|
||||
|
||||
function SymbolLinks(this: SymbolLinks) {
|
||||
}
|
||||
|
||||
function NodeLinks(this: NodeLinks) {
|
||||
this.flags = 0;
|
||||
}
|
||||
|
||||
export function getNodeId(node: Node): number {
|
||||
if (!node.id) {
|
||||
node.id = nextNodeId;
|
||||
@@ -1271,12 +1278,12 @@ namespace ts {
|
||||
function getSymbolLinks(symbol: Symbol): SymbolLinks {
|
||||
if (symbol.flags & SymbolFlags.Transient) return <TransientSymbol>symbol;
|
||||
const id = getSymbolId(symbol);
|
||||
return symbolLinks[id] || (symbolLinks[id] = {});
|
||||
return symbolLinks[id] || (symbolLinks[id] = new (<any>SymbolLinks)());
|
||||
}
|
||||
|
||||
function getNodeLinks(node: Node): NodeLinks {
|
||||
const nodeId = getNodeId(node);
|
||||
return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 } as NodeLinks);
|
||||
return nodeLinks[nodeId] || (nodeLinks[nodeId] = new (<any>NodeLinks)());
|
||||
}
|
||||
|
||||
function isGlobalSourceFile(node: Node) {
|
||||
|
||||
Reference in New Issue
Block a user