aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-10-13 00:13:20 +0000
committerEvan Huus <eapache@gmail.com>2013-10-13 00:13:20 +0000
commitf65ab9499b78bb82cbfd3461e8fd679345d9e5a9 (patch)
treeff41c456ec554d525b7d53a2acde362a6d3101c2 /epan/tvbuff.c
parent6390f337720db512b78ce5902cc9e3aaaf2e243b (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.c36
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;
}
}