diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2015-02-06 13:52:37 -0500 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-02-11 09:14:50 +0000 |
commit | a837570d02dca2ad94ff5046b13592d84a12a345 (patch) | |
tree | 0a06b1d9a1c7c1e6bc67f57412f7adc3a2a1db71 /wsutil/ws_mempbrk.c | |
parent | a618f1c0d63fd290cbdc93272beaf1ca7e838027 (diff) | |
download | wireshark-a837570d02dca2ad94ff5046b13592d84a12a345.tar.gz |
Combine SSE and pre-compiled patterns for faster pbrk
This combines the SSE4.2 instructions usage, with pre-compiled
pattern searching usage, for a faster pbrk search method.
Testing against large files of HTTP and SIP, there is about
a 5% performance improvement by using pre-"compiled" patterns
for guint8_pbrk() instead of passing it the search string and
having it build the match array every time.
Similar to regular expressions, "compiling" the pattern match array
in advance only once and using the "compiled" patterns for
the searches is faster than compiling it every time.
Change-Id: Ifcbc14a6c93f32d15663a10d974bacdca5119a8e
Ping-Bug: 10798
Reviewed-on: https://code.wireshark.org/review/6990
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wsutil/ws_mempbrk.c')
-rw-r--r-- | wsutil/ws_mempbrk.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/wsutil/ws_mempbrk.c b/wsutil/ws_mempbrk.c index 8ad1a17e78..6ed9ebcd9e 100644 --- a/wsutil/ws_mempbrk.c +++ b/wsutil/ws_mempbrk.c @@ -36,50 +36,54 @@ #include <glib.h> #include "ws_symbol_export.h" +#include "ws_mempbrk.h" + + +void +tvb_pbrk_compile(tvb_pbrk_pattern* pattern, const gchar *needles) +{ + const gchar *n = needles; + while (*n) { + pattern->patt[(int)*n] = 1; + n++; + } + #ifdef HAVE_SSE4_2 -#include "ws_cpuid.h" + ws_mempbrk_sse42_compile(pattern, needles); #endif -#include "ws_mempbrk.h" +} + const guint8 * -_ws_mempbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles) +ws_mempbrk_exec(const guint8* haystack, size_t haystacklen, const tvb_pbrk_pattern* pattern, guchar *found_needle) { - gchar tmp[256] = { 0 }; - const guint8 *haystack_end; + const guint8 *haystack_end = haystack + haystacklen; - while (*needles) - tmp[*needles++] = 1; + while (haystack < haystack_end) { + if (pattern->patt[*haystack]) { + if (found_needle) + *found_needle = *haystack; + return haystack; + } + haystack++; + } - haystack_end = haystack + haystacklen; - while (haystack < haystack_end) { - if (tmp[*haystack]) - return haystack; - haystack++; - } - - return NULL; + return NULL; } + WS_DLL_PUBLIC const guint8 * -ws_mempbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles) +tvb_pbrk_exec(const guint8* haystack, size_t haystacklen, const tvb_pbrk_pattern* pattern, guchar *found_needle) { #ifdef HAVE_SSE4_2 - static int have_sse42 = -1; + if (haystacklen >= 16 && pattern->use_sse42) + return ws_mempbrk_sse42_exec(haystack, haystacklen, pattern, found_needle); #endif - if (*needles == 0) - return NULL; - -#ifdef HAVE_SSE4_2 - if G_UNLIKELY(have_sse42 < 0) - have_sse42 = ws_cpuid_sse42(); - if (haystacklen >= 16 && have_sse42) - return _ws_mempbrk_sse42(haystack, haystacklen, needles); -#endif - - return _ws_mempbrk(haystack, haystacklen, needles); + return ws_mempbrk_exec(haystack, haystacklen, pattern, found_needle); } + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * |