aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wmem
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2014-05-02 09:53:33 -0400
committerAnders Broman <a.broman58@gmail.com>2014-05-02 14:34:50 +0000
commitf181756640f2ac6e14a2034637b00eb4faa28aee (patch)
treef50d701ca4e7f0a30241e2006427e404025db47f /epan/wmem
parent34fa16971919e9f71ef7dde018253e5b3c0e0bc5 (diff)
Optimize wmem_strbuf_grow.
As suggested by Anders, in the case of repeated calls to wmem_strbuf_append_c (and other functions which append very little data) the growth check was a substantial portion of the over-all running time. By short-circuiting the check in the case where growth isn't needed (as opposed to letting it fall-through naturally) we shave ~25% off the cost of such repeated calls in my benchmarks. The function (wmem_strbuf_grow) is inline, so the compiler should be able to optimize each caller individually for the short-circuit. Change-Id: I76419020f4d8fa675906eb77798969b6c61c7732 Reviewed-on: https://code.wireshark.org/review/1467 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/wmem')
-rw-r--r--epan/wmem/wmem_strbuf.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/epan/wmem/wmem_strbuf.c b/epan/wmem/wmem_strbuf.c
index 41f13a9aff..bd074e7584 100644
--- a/epan/wmem/wmem_strbuf.c
+++ b/epan/wmem/wmem_strbuf.c
@@ -106,6 +106,14 @@ wmem_strbuf_grow(wmem_strbuf_t *strbuf, const gsize to_add)
{
gsize new_alloc_len, new_len;
+ /* short-circuit for efficiency if we have room already; greatly speeds up
+ * repeated calls to wmem_strbuf_append_c and others which grow a little bit
+ * at a time.
+ */
+ if (WMEM_STRBUF_ROOM(strbuf) >= to_add) {
+ return;
+ }
+
new_alloc_len = strbuf->alloc_len;
new_len = strbuf->len + to_add;