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>
This commit is contained in:
parent
2944d8b97c
commit
c025152c5c
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue