Piotr Caban : msvcrt: Optimize tolower function when locale was never changed.
Alexandre Julliard
julliard at winehq.org
Wed Jan 23 17:11:34 CST 2019
Module: wine
Branch: master
Commit: e867af3bfeb5fc50d76cf26816d294d5342fe48c
URL: https://source.winehq.org/git/wine.git/?a=commit;h=e867af3bfeb5fc50d76cf26816d294d5342fe48c
Author: Piotr Caban <piotr at codeweavers.com>
Date: Wed Jan 23 11:59:05 2019 +0100
msvcrt: Optimize tolower function when locale was never changed.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/ctype.c | 4 +++-
dlls/msvcrt/locale.c | 4 ++++
dlls/msvcrt/msvcrt.h | 1 +
dlls/msvcrt/tests/string.c | 14 ++++++++++----
4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/dlls/msvcrt/ctype.c b/dlls/msvcrt/ctype.c
index 758411a..17b12e2 100644
--- a/dlls/msvcrt/ctype.c
+++ b/dlls/msvcrt/ctype.c
@@ -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);
}
/*********************************************************************
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 1e56395..a1e827d 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -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;
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index fc91066..02b8628 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -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
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index e80a518..a159132 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -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")) {
More information about the wine-cvs
mailing list