From: Jérôme Benoit Date: Sat, 8 Jun 2024 16:57:16 +0000 (+0200) Subject: perf: add fastpath in array sorting helper X-Git-Tag: v1.3.5~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8bfa4d2be3f3817654791f166f4aab1b02485005;p=e-mobility-charging-stations-simulator.git perf: add fastpath in array sorting helper Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9d021ecb..9a06c64e 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -328,6 +328,9 @@ export const getWebSocketCloseEventStatusString = (code: number): string => { } export const isArraySorted = (array: T[], compareFn: (a: T, b: T) => number): boolean => { + if (array.length <= 1) { + return true + } for (let index = 0; index < array.length - 1; ++index) { if (compareFn(array[index], array[index + 1]) > 0) { return false