[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


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@356512 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/support/win32/locale_win32.cpp b/src/support/win32/locale_win32.cpp
index c11adfe..d02d7ff 100644
--- a/src/support/win32/locale_win32.cpp
+++ b/src/support/win32/locale_win32.cpp
@@ -87,10 +87,16 @@
 
 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;
 }