From 987a271e93d5629e8ae15ad32129095655047a44 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 18 Feb 2022 15:41:21 -0800 Subject: [PATCH] Performance optimization removing dump --- .../src/components/layout/RootedTreeSet.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/mindplot/src/components/layout/RootedTreeSet.ts b/packages/mindplot/src/components/layout/RootedTreeSet.ts index bc803331..8fb53fce 100644 --- a/packages/mindplot/src/components/layout/RootedTreeSet.ts +++ b/packages/mindplot/src/components/layout/RootedTreeSet.ts @@ -55,10 +55,9 @@ class RootedTreeSet { */ add(node: Node) { $assert(node, 'node can not be null'); - $assert( - !this.find(node.getId(), false), - `node already exits with this id. Id:${node.getId()}: ${this.dump()}`, - ); + if (this.find(node.getId(), false)) { + throw new Error(`node already exits with this id. Id:${node.getId()}: ${this.dump()}`); + } $assert(!node._children, 'node already added'); this._rootNodes.push(this._decodate(node)); } @@ -130,10 +129,11 @@ class RootedTreeSet { break; } } - $assert( - validate ? result : true, - `node could not be found id:${id}\n,RootedTreeSet${this.dump()}`, - ); + + if (validate && !result) { + throw new Error(`node could not be found id:${id}\n,RootedTreeSet${this.dump()}`); + } + return result; } @@ -258,8 +258,8 @@ class RootedTreeSet { } /** - * @return result - */ + * @return result + */ dump() { const branches = this._rootNodes; let result = '';