From b672e4a2a6053acc9f0ec5f47baaf12be0069c1e Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Fri, 18 Oct 2024 18:37:13 -0500 Subject: [PATCH] slight optimization `stringifyObject` does not need to be re-run for every selected value. Co-authored-by: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> --- .../Form/Elements/FormSelectMany/worker/selectManyMain.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/components/Form/Elements/FormSelectMany/worker/selectManyMain.ts b/client/src/components/Form/Elements/FormSelectMany/worker/selectManyMain.ts index af9ddd99f6cb..34c043022938 100644 --- a/client/src/components/Form/Elements/FormSelectMany/worker/selectManyMain.ts +++ b/client/src/components/Form/Elements/FormSelectMany/worker/selectManyMain.ts @@ -47,8 +47,11 @@ export function main(options: UnwrapNestedRefs): UnwrapNes if (options.maintainSelectionOrder) { const selectedValuesArray = Array.from(selectedValues); selectedOptionsFiltered.sort((a, b) => { - const aIndex = selectedValuesArray.findIndex((v) => v === stringifyObject(a.value)); - const bIndex = selectedValuesArray.findIndex((v) => v === stringifyObject(b.value)); + const aAsString = stringifyObject(a.value); + const bAsString = stringifyObject(b.value); + + const aIndex = selectedValuesArray.findIndex((v) => v === aAsString); + const bIndex = selectedValuesArray.findIndex((v) => v === bAsString); return aIndex - bIndex; }); }