From 8bfa4d2be3f3817654791f166f4aab1b02485005 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 8 Jun 2024 18:57:16 +0200 Subject: [PATCH] perf: add fastpath in array sorting helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Utils.ts | 3 +++ 1 file changed, 3 insertions(+) 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 -- 2.34.1