From 3a5ce8886ff1bda66c2d705ee5257199c8d432ca Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Thu, 5 Jan 2023 14:07:08 +0000 Subject: [PATCH 1/2] perf(core): make classDeclaration validation more CPU efficient Signed-off-by: Matt Roberts --- .../lib/introspect/classdeclaration.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 6a6560910b..2efba065be 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -212,16 +212,12 @@ class ClassDeclaration extends Decorated { super.validate(); const declarations = this.getModelFile().getAllDeclarations(); - for (let n = 0; n < declarations.length; n++) { - let declaration = declarations[n]; - - // check we don't have an asset with the same name - for (let i = n + 1; i < declarations.length; i++) { - let otherDeclaration = declarations[i]; - if (declaration.getFullyQualifiedName() === otherDeclaration.getFullyQualifiedName()) { - throw new IllegalModelException(`Duplicate class name ${declaration.getName()}`); - } - } + const declarationNames = declarations.map(d => d.getFullyQualifiedName()); + const uniqueNames = [...new Set(declarationNames)]; + + if (uniqueNames.length !== declarationNames.length) { + const duplicateElements = declarationNames.filter((item, index) => declarationNames.indexOf(item) !== index) + throw new IllegalModelException(`Duplicate class name ${duplicateElements[0]}`); } // if we have a super type make sure it exists From dfd71ece5912bf450853ca16409199386684a864 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Thu, 5 Jan 2023 14:16:55 +0000 Subject: [PATCH 2/2] fix(core): fix linting Signed-off-by: Matt Roberts --- packages/concerto-core/lib/introspect/classdeclaration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 2efba065be..03131264ed 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -216,7 +216,7 @@ class ClassDeclaration extends Decorated { const uniqueNames = [...new Set(declarationNames)]; if (uniqueNames.length !== declarationNames.length) { - const duplicateElements = declarationNames.filter((item, index) => declarationNames.indexOf(item) !== index) + const duplicateElements = declarationNames.filter((item, index) => declarationNames.indexOf(item) !== index); throw new IllegalModelException(`Duplicate class name ${duplicateElements[0]}`); }