From a0feccdf5692389920206444aea6b34105554c7f Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Tue, 19 Mar 2019 20:30:58 +0000 Subject: [libc++] Speed up certain locale functions on Windows The issue is that __libcpp_locale_guard makes some slow calls to setlocale(). This change avoids using __libcpp_locale_guard in snprintf_l(). Fixes https://bugs.llvm.org/show_bug.cgi?id=41131 Differential Revision: https://reviews.llvm.org/D59525 llvm-svn: 356512 --- libcxx/src/support/win32/locale_win32.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libcxx/src/support/win32/locale_win32.cpp') diff --git a/libcxx/src/support/win32/locale_win32.cpp b/libcxx/src/support/win32/locale_win32.cpp index c11adfe4cda..d02d7ffc3cd 100644 --- a/libcxx/src/support/win32/locale_win32.cpp +++ b/libcxx/src/support/win32/locale_win32.cpp @@ -87,10 +87,16 @@ int wctob_l( wint_t c, locale_t loc ) int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...) { +#if !defined(_LIBCPP_MSVCRT) __libcpp_locale_guard __current(loc); +#endif va_list ap; va_start( ap, format ); +#if defined(_LIBCPP_MSVCRT) + int result = _vsnprintf_l( ret, n, format, loc, ap ); +#else int result = vsnprintf( ret, n, format, ap ); +#endif va_end(ap); return result; } -- cgit v1.2.3