[PATCH 4/5] msvcrt: Create global lc_time_curr and use when possible.

Jeff Smith whydoubt at gmail.com
Mon Dec 2 11:52:03 CST 2019


Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
 dlls/msvcrt/locale.c | 23 +++++++++++++----------
 dlls/msvcrt/msvcrt.h |  1 +
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 5a8d99493e..277e7802af 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -42,6 +42,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
 #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
 #define MAX_LOCALE_LENGTH 256
 MSVCRT__locale_t MSVCRT_locale = NULL;
+MSVCRT___lc_time_data *MSVCRT_time_curr = NULL;
 unsigned short *MSVCRT__pctype = NULL;
 unsigned int MSVCRT___lc_codepage = 0;
 int MSVCRT___lc_collate_cp = 0;
@@ -829,7 +830,8 @@ void free_locinfo(MSVCRT_pthreadlocinfo locinfo)
     MSVCRT_free(locinfo->pclmap);
     MSVCRT_free(locinfo->pcumap);
 
-    MSVCRT_free(locinfo->lc_time_curr);
+    if(locinfo->lc_time_curr != MSVCRT_time_curr)
+        MSVCRT_free(locinfo->lc_time_curr);
 
     MSVCRT_free(locinfo);
 }
@@ -1567,20 +1569,20 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
                 lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME])) {
         locinfo->lc_handle[MSVCRT_LC_TIME] = old_locinfo->lc_handle[MSVCRT_LC_TIME];
         locinfo->lc_id[MSVCRT_LC_TIME].wCodePage = old_locinfo->lc_id[MSVCRT_LC_TIME].wCodePage;
-    } else {
-        if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) {
-            if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME],
-                        cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME))
-                goto failed;
+    } else if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) {
+        if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME],
+                    cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME))
+            goto failed;
 
-            if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME))
-                goto failed;
-        } else
-            locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C");
+        if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME))
+            goto failed;
 
         locinfo->lc_time_curr = create_time_data(lcid[MSVCRT_LC_TIME]);
         if(!locinfo->lc_time_curr)
             goto failed;
+    } else {
+        locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C");
+        locinfo->lc_time_curr = MSVCRT_time_curr;
     }
 
     return locinfo;
@@ -1962,6 +1964,7 @@ BOOL msvcrt_init_locale(void)
 {
     int i;
 
+    MSVCRT_time_curr = create_time_data(0);
     _lock_locales();
     MSVCRT_locale = MSVCRT__create_locale(0, "C");
     _unlock_locales();
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 4a7e6f4219..445c28178a 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -305,6 +305,7 @@ extern thread_data_t *msvcrt_get_thread_data(void) DECLSPEC_HIDDEN;
 
 LCID MSVCRT_locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN;
 extern MSVCRT__locale_t MSVCRT_locale DECLSPEC_HIDDEN;
+extern MSVCRT___lc_time_data *MSVCRT_time_curr DECLSPEC_HIDDEN;
 extern unsigned int MSVCRT___lc_codepage;
 extern int MSVCRT___lc_collate_cp;
 extern WORD MSVCRT__ctype [257];
-- 
2.23.0




More information about the wine-devel mailing list