diff options
author | Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> | 2009-08-16 10:53:47 +0000 |
---|---|---|
committer | Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> | 2009-08-16 10:53:47 +0000 |
commit | fe6f8b92c7f1f72a0eb677f01899f1dfa07b5342 (patch) | |
tree | 5b238ca1101ce3563203839bb86e177ab1158fe6 /epan | |
parent | c795851bebb1ed1d7a0c0302c295b55687aa315c (diff) |
Add a new function, tvb_new_subset_remaining(), which is a sligtly optimized version of tvb_new_subset(). The latter can be mapped to the former by tvb_new_subset(tvb, offset, -1 /* backing_length */, -1 /* reported_length */). We can disable some bounds checking because 'backing_length' and 'reported_length' are hardcoded to -1.
The current implementation of tvb_new_subset_remaining() only has the THROW_ON(reported_length < 1) check removed when compared to tvb_new_subset(). So there's room for improvement in this function. We should be able to disable some more (redundant) bounds checking.
svn path=/trunk/; revision=29445
Diffstat (limited to 'epan')
-rw-r--r-- | epan/tvbuff.c | 38 | ||||
-rw-r--r-- | epan/tvbuff.h | 4 |
2 files changed, 39 insertions, 3 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c index b875446642..25dc16f675 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -145,6 +145,16 @@ tvb_new(tvbuff_type type) return tvb; } +static tvbuff_t* +tvb_new_with_subset(tvbuff_type type, guint subset_tvb_offset, guint subset_tvb_length) +{ + tvbuff_t *tvb = tvb_new(type); + tvb->tvbuffs.subset.offset = subset_tvb_offset; + tvb->tvbuffs.subset.length = subset_tvb_length; + + return tvb; +} + void tvb_free(tvbuff_t* tvb) { @@ -513,9 +523,7 @@ tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint &subset_tvb_offset, &subset_tvb_length); - tvb = tvb_new(TVBUFF_SUBSET); - tvb->tvbuffs.subset.offset = subset_tvb_offset; - tvb->tvbuffs.subset.length = subset_tvb_length; + tvb = tvb_new_with_subset(TVBUFF_SUBSET, subset_tvb_offset, subset_tvb_length); tvb_set_subset_no_exceptions(tvb, backing, reported_length); @@ -528,6 +536,30 @@ tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint return tvb; } +tvbuff_t* +tvb_new_subset_remaining(tvbuff_t *backing, gint backing_offset) +{ + tvbuff_t *tvb; + guint subset_tvb_offset; + guint subset_tvb_length; + + check_offset_length(backing->length, backing->reported_length, backing_offset, -1 /* backing_length */, + &subset_tvb_offset, + &subset_tvb_length); + + tvb = tvb_new_with_subset(TVBUFF_SUBSET, subset_tvb_offset, subset_tvb_length); + + tvb_set_subset_no_exceptions(tvb, backing, -1 /* reported_length */); + + /* + * The top-level data source of this tvbuff is the top-level + * data source of its parent. + */ + tvb->ds_tvb = backing->ds_tvb; + + return tvb; +} + void tvb_composite_append(tvbuff_t* tvb, tvbuff_t* member) { diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 06adc07c8f..8632b4da28 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -241,6 +241,10 @@ extern void tvb_set_subset(tvbuff_t* tvb, tvbuff_t* backing, extern tvbuff_t* tvb_new_subset(tvbuff_t* backing, gint backing_offset, gint backing_length, gint reported_length); +/** Similar to tvb_new_subset() but with backing_length and reported_length set to -1. + * Can throw ReportedBoundsError. */ +extern tvbuff_t* tvb_new_subset_remaining(tvbuff_t* backing, + gint backing_offset); /** Both tvb_composite_append and tvb_composite_prepend can throw * BoundsError if member_offset/member_length goes beyond bounds of |