msvcrt: Pass temporary locale to MSVCRT__towlower_l.

When not provided, instead of calling get_locinfo on every character.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2020-11-10 16:58:44 +01:00 committed by Alexandre Julliard
parent faf92fdedb
commit 0a2635611a
1 changed files with 24 additions and 2 deletions

View File

@ -119,16 +119,22 @@ int CDECL MSVCRT_towlower(MSVCRT_wint_t c)
INT CDECL MSVCRT__wcsicmp_l(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2, MSVCRT__locale_t locale) INT CDECL MSVCRT__wcsicmp_l(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2, MSVCRT__locale_t locale)
{ {
MSVCRT__locale_tstruct tmp = {0};
MSVCRT_wchar_t c1, c2; MSVCRT_wchar_t c1, c2;
if(!MSVCRT_CHECK_PMT(str1 != NULL) || !MSVCRT_CHECK_PMT(str2 != NULL)) if(!MSVCRT_CHECK_PMT(str1 != NULL) || !MSVCRT_CHECK_PMT(str2 != NULL))
return MSVCRT__NLSCMPERROR; return MSVCRT__NLSCMPERROR;
if(!locale)
locale = get_current_locale_noalloc(&tmp);
do do
{ {
c1 = MSVCRT__towlower_l(*str1++, locale); c1 = MSVCRT__towlower_l(*str1++, locale);
c2 = MSVCRT__towlower_l(*str2++, locale); c2 = MSVCRT__towlower_l(*str2++, locale);
} while(c1 && (c1 == c2)); } while(c1 && (c1 == c2));
free_locale_noalloc(&tmp);
return c1 - c2; return c1 - c2;
} }
@ -146,19 +152,25 @@ INT CDECL MSVCRT__wcsicmp( const MSVCRT_wchar_t* str1, const MSVCRT_wchar_t* str
INT CDECL MSVCRT__wcsnicmp_l(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2, INT CDECL MSVCRT__wcsnicmp_l(const MSVCRT_wchar_t *str1, const MSVCRT_wchar_t *str2,
MSVCRT_size_t n, MSVCRT__locale_t locale) MSVCRT_size_t n, MSVCRT__locale_t locale)
{ {
MSVCRT__locale_tstruct tmp = {0};
MSVCRT_wchar_t c1, c2; MSVCRT_wchar_t c1, c2;
if (!n) if (!n)
return 0; return 0;
if(!MSVCRT_CHECK_PMT(str1 != NULL) || !MSVCRT_CHECK_PMT(str2 != NULL)) if(!MSVCRT_CHECK_PMT(str1 != NULL) || !MSVCRT_CHECK_PMT(str2 != NULL))
return MSVCRT__NLSCMPERROR; return MSVCRT__NLSCMPERROR;
if(!locale)
locale = get_current_locale_noalloc(&tmp);
do do
{ {
c1 = MSVCRT__towlower_l(*str1++, locale); c1 = MSVCRT__towlower_l(*str1++, locale);
c2 = MSVCRT__towlower_l(*str2++, locale); c2 = MSVCRT__towlower_l(*str2++, locale);
} while(--n && c1 && (c1 == c2)); } while(--n && c1 && (c1 == c2));
free_locale_noalloc(&tmp);
return c1 - c2; return c1 - c2;
} }
@ -397,6 +409,7 @@ MSVCRT_wchar_t* CDECL MSVCRT__wcsupr( MSVCRT_wchar_t *str )
*/ */
int CDECL MSVCRT__wcslwr_s_l( MSVCRT_wchar_t* str, MSVCRT_size_t n, MSVCRT__locale_t locale ) int CDECL MSVCRT__wcslwr_s_l( MSVCRT_wchar_t* str, MSVCRT_size_t n, MSVCRT__locale_t locale )
{ {
MSVCRT__locale_tstruct tmp = {0};
MSVCRT_wchar_t* ptr = str; MSVCRT_wchar_t* ptr = str;
if (!str || !n) if (!str || !n)
@ -406,13 +419,22 @@ int CDECL MSVCRT__wcslwr_s_l( MSVCRT_wchar_t* str, MSVCRT_size_t n, MSVCRT__loca
return MSVCRT_EINVAL; return MSVCRT_EINVAL;
} }
if(!locale)
locale = get_current_locale_noalloc(&tmp);
while (n--) while (n--)
{ {
if (!*ptr) return 0; if (!*ptr)
{
free_locale_noalloc(&tmp);
return 0;
}
*ptr = MSVCRT__towlower_l(*ptr, locale); *ptr = MSVCRT__towlower_l(*ptr, locale);
ptr++; ptr++;
} }
free_locale_noalloc(&tmp);
/* MSDN claims that the function should return and set errno to /* MSDN claims that the function should return and set errno to
* ERANGE, which doesn't seem to be true based on the tests. */ * ERANGE, which doesn't seem to be true based on the tests. */
*str = '\0'; *str = '\0';