Skip to content

Commit 5453e81

Browse files
committed
Improve performance
1 parent 8e88532 commit 5453e81

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/interop/ecore.ts

+25-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ensurePackage,
88
getNodeDefinition,
99
Node,
10-
NODE_TYPES,
10+
NODE_TYPES, NodeDefinition,
1111
PackageDescription,
1212
PropertyDefinition,
1313
registerNodeDefinition,
@@ -828,20 +828,27 @@ export class ECoreNode extends NodeAdapter {
828828

829829
parent?: ECoreNode;
830830

831-
constructor(public eo: ECore.EObject) {
831+
constructor(public eo: ECore.EObject, parent?: ECoreNode) {
832832
super();
833-
const container = this.eo.eContainer;
834-
if (container?.isKindOf(THE_NODE_ECLASS_V2) || container?.isKindOf(THE_NODE_ECLASS_V1)) {
833+
const container = eo.eContainer;
834+
if (parent) {
835+
this.parent = parent;
836+
} else if (container?.isKindOf(THE_NODE_ECLASS_V2) || container?.isKindOf(THE_NODE_ECLASS_V1)) {
835837
this.parent = new ECoreNode(container);
836838
}
837839
}
838840

841+
private __nodeDefinition?: NodeDefinition;
842+
839843
get nodeDefinition() {
840-
return {
841-
package: this.eo.eClass.eContainer.get("name") as string,
842-
name: this.eo.eClass.get("name") as string,
843-
properties: this.getProperties()
844-
};
844+
if (!this.__nodeDefinition) {
845+
this.__nodeDefinition = {
846+
package: this.eo.eClass.eContainer.get("name") as string,
847+
name: this.eo.eClass.get("name") as string,
848+
properties: this.getProperties()
849+
};
850+
}
851+
return this.__nodeDefinition;
845852
}
846853

847854
get(...path: string[]): NodeAdapter | undefined {
@@ -869,8 +876,13 @@ export class ECoreNode extends NodeAdapter {
869876
return result;
870877
}
871878

872-
getChildren(role?: string): NodeAdapter[] {
873-
return this.getChildrenEObjects(role).map(c => new ECoreNode(c));
879+
private __children?: ECoreNode[] = undefined;
880+
881+
getChildren(role?: string): ECoreNode[] {
882+
if (this.__children === undefined) {
883+
this.__children = this.getChildrenEObjects().map(c => new ECoreNode(c, this));
884+
}
885+
return this.__children!.filter(c => !role || c.getRole() == role);
874886
}
875887

876888
getId(): string {
@@ -921,12 +933,11 @@ export class ECoreNode extends NodeAdapter {
921933
return result;
922934
}
923935

924-
protected getChildrenEObjects(role: string | undefined) {
936+
protected getChildrenEObjects() {
925937
return this.eo.eContents()
926938
.filter((c) => c.isKindOf(THE_NODE_ECLASS_V2) || c.isKindOf(THE_NODE_ECLASS_V1))
927939
.filter((c) => c.eContainingFeature.get("name") != "origin")
928-
.filter((c) => c.eContainingFeature.get("name") != "destination")
929-
.filter((c) => role == null || role == c.eContainingFeature.get("name"));
940+
.filter((c) => c.eContainingFeature.get("name") != "destination");
930941
}
931942

932943
isDeclaration(): boolean {

0 commit comments

Comments
 (0)