Skip to content

Commit

Permalink
Remove reflection perf (#890)
Browse files Browse the repository at this point in the history
Refactored the removeReflection so the symbolMapping is iterated once instead of per hidden reflection
  • Loading branch information
igandrews authored and aciccarello committed Nov 2, 2018
1 parent dbdbfca commit d64de97
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -222,9 +222,7 @@ export class CommentPlugin extends ConverterComponent {

if (this.hidden) {
const project = context.project;
this.hidden.forEach((reflection) => {
CommentPlugin.removeReflection(project, reflection);
});
CommentPlugin.removeReflections(project, this.hidden);
}
}

Expand Down Expand Up @@ -314,11 +312,27 @@ export class CommentPlugin extends ConverterComponent {
}
}

/**
* Remove the specified reflections from the project.
*/
static removeReflections(project: ProjectReflection, reflections: Reflection[]) {
const deletedIds: number[] = [];
reflections.forEach((reflection) => {
CommentPlugin.removeReflection(project, reflection, deletedIds);
});

for (let key in project.symbolMapping) {
if (project.symbolMapping.hasOwnProperty(key) && deletedIds.indexOf(project.symbolMapping[key]) !== -1) {
delete project.symbolMapping[key];
}
}
}

/**
* Remove the given reflection from the project.
*/
static removeReflection(project: ProjectReflection, reflection: Reflection) {
reflection.traverse((child) => CommentPlugin.removeReflection(project, child));
private static removeReflection(project: ProjectReflection, reflection: Reflection, deletedIds: number[]) {
reflection.traverse((child) => CommentPlugin.removeReflection(project, child, deletedIds));

const parent = <DeclarationReflection> reflection.parent;
parent.traverse((child: Reflection, property: TraverseProperty) => {
Expand Down Expand Up @@ -375,10 +389,7 @@ export class CommentPlugin extends ConverterComponent {
let id = reflection.id;
delete project.reflections[id];

for (let key in project.symbolMapping) {
if (project.symbolMapping.hasOwnProperty(key) && project.symbolMapping[key] === id) {
delete project.symbolMapping[key];
}
}
// keep track of the reflections that have been deleted
deletedIds.push(id);
}
}

0 comments on commit d64de97

Please sign in to comment.