msvcrt: Optimize tolower function when locale was never changed.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
(cherry picked from commit e867af3bfe)
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
oldstable
Piotr Caban 2019-01-23 11:59:05 +01:00 committed by Michael Stefaniuc
parent 8cb1de4d06
commit a6debb6796
4 changed files with 18 additions and 5 deletions

View File

@ -458,7 +458,9 @@ int CDECL MSVCRT__tolower_l(int c, MSVCRT__locale_t locale)
*/
int CDECL MSVCRT_tolower(int c)
{
return MSVCRT__tolower_l(c, NULL);
if(initial_locale)
return c>='A' && c<='Z' ? c-'A'+'a' : c;
return MSVCRT__tolower_l(c, NULL);
}
/*********************************************************************

View File

@ -48,6 +48,7 @@ int MSVCRT___lc_collate_cp = 0;
LCID MSVCRT___lc_handle[MSVCRT_LC_MAX - MSVCRT_LC_MIN + 1] = { 0 };
int MSVCRT___mb_cur_max = 1;
static unsigned char charmax = CHAR_MAX;
BOOL initial_locale = TRUE;
#define MSVCRT_LEADBYTE 0x8000
#define MSVCRT_C1_DEFINED 0x200
@ -1780,6 +1781,9 @@ char* CDECL MSVCRT_setlocale(int category, const char* locale)
_lock_locales();
if(locale[0] != 'C' || locale[1] != '\0')
initial_locale = FALSE;
if(locinfo->lc_handle[MSVCRT_LC_COLLATE]!=newlocinfo->lc_handle[MSVCRT_LC_COLLATE]
|| locinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage!=newlocinfo->lc_id[MSVCRT_LC_COLLATE].wCodePage) {
locinfo->lc_collate_cp = newlocinfo->lc_collate_cp;

View File

@ -283,6 +283,7 @@ extern MSVCRT__locale_t MSVCRT_locale DECLSPEC_HIDDEN;
extern unsigned int MSVCRT___lc_codepage;
extern int MSVCRT___lc_collate_cp;
extern WORD MSVCRT__ctype [257];
extern BOOL initial_locale DECLSPEC_HIDDEN;
void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
#if _MSVCR_VER >= 80

View File

@ -2788,13 +2788,19 @@ static void test_tolower(void)
errno = 0xdeadbeef;
ret = p_tolower((char)0xF4);
todo_wine ok(ret == (char)0xF4, "ret = %x\n", ret);
todo_wine ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ok(ret == (char)0xF4, "ret = %x\n", ret);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
errno = 0xdeadbeef;
ret = p_tolower((char)0xD0);
todo_wine ok(ret == (char)0xD0, "ret = %x\n", ret);
todo_wine ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ok(ret == (char)0xD0, "ret = %x\n", ret);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
setlocale(LC_ALL, "C");
errno = 0xdeadbeef;
ret = p_tolower((char)0xF4);
ok(ret == (char)0xF4, "ret = %x\n", ret);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
/* test C locale after setting locale */
if(!setlocale(LC_ALL, "us")) {