From 83f696d217367e0f2a0578dbc6a4e21f551c19cf Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 26 Sep 2023 12:33:07 -0700 Subject: [PATCH] util: Fix inefficient RegExp construction. Signed-off-by: Anders Kaseorg --- web/src/util.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/src/util.ts b/web/src/util.ts index 7ff1315b35..c7106a9c79 100644 --- a/web/src/util.ts +++ b/web/src/util.ts @@ -215,8 +215,9 @@ export const move_array_elements_to_front = function util_move_array_elements_to // check by the userAgent string if a user's client is likely mobile. export function is_mobile(): boolean { - const regex = "Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini"; - return new RegExp(regex, "i").test(window.navigator.userAgent); + return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test( + window.navigator.userAgent, + ); } export function sorted_ids(ids: number[]): number[] {