Skip to content

Commit

Permalink
perf(core): make classDeclaration validation more CPU efficient (#582)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Roberts <[email protected]>
  • Loading branch information
mttrbrts authored Jan 5, 2023
1 parent 2a0554c commit 760b078
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/concerto-core/lib/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 760b078

Please sign in to comment.