[libcxx-commits] [PATCH] D59525: Speed up certain locale functions on Windows

Tom Anderson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 18 17:39:29 PDT 2019


thomasanderson created this revision.
thomasanderson added reviewers: EricWF, mclow.lists.
Herald added a subscriber: ldionne.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41131


Repository:
  rCXX libc++

https://reviews.llvm.org/D59525

Files:
  include/__locale
  src/support/win32/locale_win32.cpp


Index: src/support/win32/locale_win32.cpp
===================================================================
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -87,10 +87,9 @@
 
 int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
 {
-    __libcpp_locale_guard __current(loc);
     va_list ap;
     va_start( ap, format );
-    int result = vsnprintf( ret, n, format, ap );
+    int result = _vsprintf_s_l( ret, n, format, loc, ap );
     va_end(ap);
     return result;
 }
Index: include/__locale
===================================================================
--- include/__locale
+++ include/__locale
@@ -64,27 +64,14 @@
 struct __libcpp_locale_guard {
     __libcpp_locale_guard(locale_t __l) :
         __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)),
-        __locale_collate(setlocale(LC_COLLATE, __l.__get_locale())),
-        __locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())),
-        __locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())),
-        __locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())),
-        __locale_time(setlocale(LC_TIME, __l.__get_locale()))
-        // LC_MESSAGES is not supported on Windows.
+        __locale_all(setlocale(LC_ALL, __l.__get_locale()))
     {}
     ~__libcpp_locale_guard() {
-        setlocale(LC_COLLATE, __locale_collate);
-        setlocale(LC_CTYPE, __locale_ctype);
-        setlocale(LC_MONETARY, __locale_monetary);
-        setlocale(LC_NUMERIC, __locale_numeric);
-        setlocale(LC_TIME, __locale_time);
+        setlocale(LC_ALL, __locale_all);
         _configthreadlocale(__status);
     }
     int __status;
-    char* __locale_collate;
-    char* __locale_ctype;
-    char* __locale_monetary;
-    char* __locale_numeric;
-    char* __locale_time;
+    char* __locale_all;
 };
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59525.191218.patch
Type: text/x-patch
Size: 1849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190319/7197ef16/attachment.bin>


More information about the libcxx-commits mailing list