From 01e29f6e9b28310dd151caf5694016995e3e7d67 Mon Sep 17 00:00:00 2001 From: YOMAN1792 <94007829+YOMAN1792@users.noreply.github.com> Date: Thu, 8 May 2025 10:33:03 -0400 Subject: [PATCH] refactor(locale): improve performance and type safety in IsValidLocaleString - Replaced `ipairs` with a numeric `for` loop in the UTF-8 validation step for better performance. - Stored `validRanges[i]` in a local `range` variable to avoid duplicate table lookups. - Added a call to `ESX.ValidateType(str, 'string')` to ensure input is of type string before processing. These changes improve both performance and code safety. --- [core]/es_extended/shared/functions.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/[core]/es_extended/shared/functions.lua b/[core]/es_extended/shared/functions.lua index c24ead38..7da3e887 100644 --- a/[core]/es_extended/shared/functions.lua +++ b/[core]/es_extended/shared/functions.lua @@ -214,6 +214,10 @@ end ---@param str string ---@return boolean function ESX.IsValidLocaleString(str) + if not ESX.ValidateType(str, 'string') then + return false + end + local locale = string.lower(Config.Locale) local defaultRanges ={ @@ -265,7 +269,8 @@ function ESX.IsValidLocaleString(str) for _, code in utf8.codes(str) do local isValid = false - for _, range in ipairs(validRanges) do + for i = 1, #validRanges do + local range = validRanges[i] if code >= range[1] and code <= range[2] then isValid = true break