From 37c772ff8c0e3aca54923324b05754391f09d6de Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Mon, 7 Dec 2020 15:33:47 -0700 Subject: [PATCH] more efficient uniqueness check --- ui/src/app/app-config/config-cursor.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ui/src/app/app-config/config-cursor.ts b/ui/src/app/app-config/config-cursor.ts index 337d7dfc6..0082ab9b4 100644 --- a/ui/src/app/app-config/config-cursor.ts +++ b/ui/src/app/app-config/config-cursor.ts @@ -223,15 +223,16 @@ export class ConfigCursor { if (max && length > max) { return spec.subtype === 'enum' ? 'Too many options selected.' : 'List is too long.' } - if (spec.subtype === 'enum') return null - for (let idx in cfg) { + for (let idx = 0; idx < cfg.length; idx++) { let cursor = this.seekNext(idx) - if (cursor.checkInvalid()) { - return `Item #${Number(idx) + 1} is invalid. ${cursor.checkInvalid()}.` + const invalid = cursor.checkInvalid() + if (invalid) { + return `Item #${idx + 1} is invalid. ${invalid}.` } - for (let idx2 in cfg) { - if (idx !== idx2 && cursor.equals(this.seekNext(idx2))) { - return `Item #${Number(idx) + 1} is not unique. ${(cursor.cachedSpec as ValueSpecObject).uniqueBy} must be unique.` + if (spec.subtype === 'enum') continue + for (let idx2 = idx + 1; idx2 < cfg.length; idx2++) { + if (cursor.equals(this.seekNext(idx2))) { + return `Item #${idx + 1} is not unique. ${JSON.stringify((cursor.cachedSpec as ValueSpecObject).uniqueBy)} must be unique.` } } }