diff options
author | Gerald Combs <gerald@wireshark.org> | 2016-04-08 09:38:54 -0700 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-04-09 10:44:17 +0000 |
commit | a8ebc3dcf541c7b5a7d7e0e315dea432dcab7279 (patch) | |
tree | 59f12d75dbe23835a07f7255fc7385392f886e57 /epan/wmem/wmem_strutl.c | |
parent | c5782e0d412c38a7338a3f8862dee0c248aab227 (diff) |
Wmem: Use the native v*printf routines on Windows.
GLib's v*printf routines are close to unreasonably slow on
Windows. Use the native CRT routines in wmem_strdup_vprintf and
wmem_strbuf_append_vprintf on that platform.
Change-Id: I5e94aa6fe47434e5a18f3a4d5b6b24ebe71499c1
Reviewed-on: https://code.wireshark.org/review/14868
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/wmem/wmem_strutl.c')
-rw-r--r-- | epan/wmem/wmem_strutl.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/epan/wmem/wmem_strutl.c b/epan/wmem/wmem_strutl.c index c35f2e68f0..009abf1d80 100644 --- a/epan/wmem/wmem_strutl.c +++ b/epan/wmem/wmem_strutl.c @@ -26,6 +26,10 @@ #include <string.h> #include <stdarg.h> +#ifdef _WIN32 +#include <stdio.h> +#endif + #include <glib.h> #include "wmem_core.h" @@ -86,6 +90,7 @@ wmem_strdup_printf(wmem_allocator_t *allocator, const gchar *fmt, ...) * in my test file all strings was less than 72 characters long and quite a few * over 68 characters long. Chose 80 as the default. */ +#ifndef _WIN32 #define WMEM_STRDUP_VPRINTF_DEFAULT_BUFFER 80 gchar * wmem_strdup_vprintf(wmem_allocator_t *allocator, const gchar *fmt, va_list ap) @@ -115,6 +120,33 @@ wmem_strdup_vprintf(wmem_allocator_t *allocator, const gchar *fmt, va_list ap) return dst; } +#else /* _WIN32 */ +/* + * GLib's v*printf routines are surprisingly slow on Windows, at least with + * GLib 2.40.0. This appears to be due to GLib using the gnulib version of + * vasnprintf when compiled under MinGW. If GLib ever ends up using the + * native Windows v*printf routines this can be removed. + */ +gchar * +wmem_strdup_vprintf(wmem_allocator_t *allocator, const gchar *fmt, va_list ap) +{ + va_list ap2; + gchar *dst; + int needed_len; + + G_VA_COPY(ap2, ap); + + needed_len = _vscprintf(fmt, ap2) + 1; + + dst = (gchar *)wmem_alloc(allocator, needed_len); + + vsprintf(dst, fmt, ap2); + + va_end(ap2); + + return dst; +} +#endif /* _WIN32 */ gchar * wmem_strconcat(wmem_allocator_t *allocator, const gchar *first, ...) |