diff options
author | Jakub Zawadzki <darkjames@darkjames.pl> | 2014-07-23 08:03:03 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2014-07-24 05:42:28 +0000 |
commit | c025152c5c62eced6e66b623cf38eb4803244073 (patch) | |
tree | 68b10857ed4d8f12122184914e11786dbe8c685d /epan/tvbuff.c | |
parent | 2944d8b97ce4e046acea39589623c91b0e9bcf4e (diff) |
Micro-optimize tvbuff:
- compute_offset_and_remaining(...) is a little bit faster than
check_offset_length(.., .length_val = -1);
- tvb_find_guint8(), tvb_pbrk_guint8() - both function are limiting data to
MIN((unsigned) maxlength, tvb_len) - do the same with less count of ifs.
Change-Id: I7761d77b6282d800eea94852d5c6543aef4bc7ca
Reviewed-on: https://code.wireshark.org/review/2829
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r-- | epan/tvbuff.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 11fe105cdf..773e6e9e90 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1735,24 +1735,17 @@ tvb_find_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu { const guint8 *result; guint abs_offset; - guint tvbufflen; guint limit; + int exception; DISSECTOR_ASSERT(tvb && tvb->initialized); - check_offset_length(tvb, offset, -1, &abs_offset, &tvbufflen); + exception = compute_offset_and_remaining(tvb, offset, &abs_offset, &limit); + if (exception) + THROW(exception); /* Only search to end of tvbuff, w/o throwing exception. */ - if (maxlength == -1) { - /* No maximum length specified; search to end of tvbuff. */ - limit = tvbufflen; - } - else if (tvbufflen < (guint) maxlength) { - /* Maximum length goes past end of tvbuff; search to end - of tvbuff. */ - limit = tvbufflen; - } - else { + if (limit > (guint) maxlength) { /* Maximum length doesn't go past end of tvbuff; search to that value. */ limit = maxlength; @@ -1802,24 +1795,17 @@ tvb_pbrk_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu { const guint8 *result; guint abs_offset; - guint tvbufflen; guint limit; + int exception; DISSECTOR_ASSERT(tvb && tvb->initialized); - check_offset_length(tvb, offset, -1, &abs_offset, &tvbufflen); + exception = compute_offset_and_remaining(tvb, offset, &abs_offset, &limit); + if (exception) + THROW(exception); /* Only search to end of tvbuff, w/o throwing exception. */ - if (maxlength == -1) { - /* No maximum length specified; search to end of tvbuff. */ - limit = tvbufflen; - } - else if (tvbufflen < (guint) maxlength) { - /* Maximum length goes past end of tvbuff; search to end - of tvbuff. */ - limit = tvbufflen; - } - else { + if (limit > (guint) maxlength) { /* Maximum length doesn't go past end of tvbuff; search to that value. */ limit = maxlength; |