diff options
author | Evan Huus <eapache@gmail.com> | 2013-10-13 00:13:20 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-10-13 00:13:20 +0000 |
commit | f65ab9499b78bb82cbfd3461e8fd679345d9e5a9 (patch) | |
tree | ff41c456ec554d525b7d53a2acde362a6d3101c2 /epan/tvbuff.c | |
parent | 6390f337720db512b78ce5902cc9e3aaaf2e243b (diff) |
Order our conditionals to take advantage of the fact that we know tvb->length <=
tvb->reported_length. Small performance win on the hot path, and a bit easier to
read.
svn path=/trunk/; revision=52577
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r-- | epan/tvbuff.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index cd48276931..f472512d66 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -164,34 +164,26 @@ compute_offset(const tvbuff_t *tvb, const gint offset, guint *offset_ptr) { if (offset >= 0) { /* Positive offset - relative to the beginning of the packet. */ - if ((guint) offset > tvb->reported_length) { - if (tvb->flags & TVBUFF_FRAGMENT) { - return FragmentBoundsError; - } else { - return ReportedBoundsError; - } - } - else if ((guint) offset > tvb->length) { - return BoundsError; - } - else { + if ((guint) offset <= tvb->length) { *offset_ptr = offset; + } else if ((guint) offset <= tvb->reported_length) { + return BoundsError; + } else if (tvb->flags & TVBUFF_FRAGMENT) { + return FragmentBoundsError; + } else { + return ReportedBoundsError; } } else { /* Negative offset - relative to the end of the packet. */ - if ((guint) -offset > tvb->reported_length) { - if (tvb->flags & TVBUFF_FRAGMENT) { - return FragmentBoundsError; - } else { - return ReportedBoundsError; - } - } - else if ((guint) -offset > tvb->length) { - return BoundsError; - } - else { + if ((guint) -offset <= tvb->length) { *offset_ptr = tvb->length + offset; + } else if ((guint) -offset <= tvb->reported_length) { + return BoundsError; + } else if (tvb->flags & TVBUFF_FRAGMENT) { + return FragmentBoundsError; + } else { + return ReportedBoundsError; } } |