perf: partially replace .concat with .push (#13609)

This commit is contained in:
Federico Ciardi
2021-08-14 16:57:06 +02:00
committed by GitHub
parent 6a651e4641
commit 10640b2aad
18 changed files with 93 additions and 74 deletions

View File

@@ -16,7 +16,7 @@ export default function addComments<T extends t.Node>(
if (type === "leading") {
node[key] = comments.concat(node[key]);
} else {
node[key] = node[key].concat(comments);
node[key].push(...comments);
}
} else {
node[key] = comments;

View File

@@ -17,13 +17,14 @@ function getQualifiedName(node: t.GenericTypeAnnotation["id"]) {
* Dedupe type annotations.
*/
export default function removeTypeDuplicates(
// todo(babel-8): change type to Array<...>
nodes: ReadonlyArray<t.FlowType | false | null | undefined>,
): t.FlowType[] {
const generics = {};
const bases = {};
// store union type groups to circular references
const typeGroups = [];
const typeGroups = new Set<t.FlowType[]>();
const types = [];
@@ -47,9 +48,10 @@ export default function removeTypeDuplicates(
}
if (isUnionTypeAnnotation(node)) {
if (typeGroups.indexOf(node.types) < 0) {
if (!typeGroups.has(node.types)) {
// todo(babel-8): use .push when nodes is mutable
nodes = nodes.concat(node.types);
typeGroups.push(node.types);
typeGroups.add(node.types);
}
continue;
}

View File

@@ -15,7 +15,7 @@ export default function removeTypeDuplicates(
const bases = {};
// store union type groups to circular references
const typeGroups = [];
const typeGroups = new Set<t.TSType[]>();
const types = [];
@@ -40,9 +40,9 @@ export default function removeTypeDuplicates(
}
if (isTSUnionType(node)) {
if (typeGroups.indexOf(node.types) < 0) {
nodes = nodes.concat(node.types);
typeGroups.push(node.types);
if (!typeGroups.has(node.types)) {
nodes.push(...node.types);
typeGroups.add(node.types);
}
continue;
}