aboutsummaryrefslogtreecommitdiffstats
path: root/packet-range.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2011-04-25 19:01:05 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2011-04-25 19:01:05 +0000
commit5934fb198447b7c5748ba6c632cbd9ab4800b185 (patch)
treeafab88f8f3fcc36e017301acc871d2b614ff516c /packet-range.c
parent251085a46a40d5652ecf58dd750fb0c4c8331874 (diff)
Store the frame_data structures in a tree, rather than a linked list.
This lets us get rid of the per-frame_data-structure prev and next pointers, saving memory (at least according to Activity Monitor's report of the virtual address space size on my Snow Leopard machine, it's a noticeable saving), and lets us look up frame_data structures by frame number in O(log2(number of frames)) time rather than O(number of frames) time. It seems to take more CPU time when reading in the file, but seems to go from "finished reading in all the packets" to "displaying the packets" faster and seems to free up the frame_data structures faster when closing the file. It *is* doing more copying, currently, as we now don't allocate the frame_data structure until after the packet has passed the read filter, so that might account for the additional CPU time. (Oh, and, for what it's worth, on an LP64 platform, a frame_data structure is exactly 128 bytes long. However, there's more stuff to remove, so the power-of-2 size is not guaranteed to remain, and it's not a power-of-2 size on an ILP32 platform.) It also means we don't need GLib 2.10 or later for the two-pass mode in TShark. It also means some code in the TCP dissector that was checking pinfo->fd->next to see if it's NULL, in order to see if this is the last packet in the file, no longer works, but that wasn't guaranteed to work anyway: we might be doing a one-pass read through the capture in TShark; we might be dissecting the frame while we're reading in the packets for the first time in Wireshark; we might be doing a live capture in Wireshark; in which case packets might be prematurely considered "the last packet". #if 0 the no-longer-working tests, pending figuring out a better way of doing it. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@36849 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'packet-range.c')
-rw-r--r--packet-range.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/packet-range.c b/packet-range.c
index e6838f62f7..6e561fb0cb 100644
--- a/packet-range.c
+++ b/packet-range.c
@@ -43,7 +43,7 @@
/* (re-)calculate the packet counts (except the user specified range) */
static void packet_range_calc(packet_range_t *range) {
- guint32 current_count;
+ guint32 framenum;
guint32 mark_low;
guint32 mark_high;
guint32 displayed_mark_low;
@@ -79,11 +79,11 @@ static void packet_range_calc(packet_range_t *range) {
* data must be entered in the widget by the user.
*/
- current_count = 0;
- for(packet = cfile.plist_start; packet != NULL; packet = packet->next) {
- current_count++;
+ for(framenum = 1; framenum <= cfile.count; framenum++) {
+ packet = cap_file_find_fdata(&cfile, framenum);
+
if (cfile.current_frame == packet) {
- range->selected_packet = current_count;
+ range->selected_packet = framenum;
}
if (packet->flags.passed_dfilter) {
range->displayed_cnt++;
@@ -98,18 +98,18 @@ static void packet_range_calc(packet_range_t *range) {
range->displayed_ignored_marked_cnt++;
}
if (displayed_mark_low == 0) {
- displayed_mark_low = current_count;
+ displayed_mark_low = framenum;
}
- if (current_count > displayed_mark_high) {
- displayed_mark_high = current_count;
+ if (framenum > displayed_mark_high) {
+ displayed_mark_high = framenum;
}
}
if (mark_low == 0) {
- mark_low = current_count;
+ mark_low = framenum;
}
- if (current_count > mark_high) {
- mark_high = current_count;
+ if (framenum > mark_high) {
+ mark_high = framenum;
}
}
if (packet->flags.ignored) {
@@ -120,12 +120,11 @@ static void packet_range_calc(packet_range_t *range) {
}
}
- current_count = 0;
- for(packet = cfile.plist_start; packet != NULL; packet = packet->next) {
- current_count++;
+ for(framenum = 1; framenum <= cfile.count; framenum++) {
+ packet = cap_file_find_fdata(&cfile, framenum);
- if (current_count >= mark_low &&
- current_count <= mark_high)
+ if (framenum >= mark_low &&
+ framenum <= mark_high)
{
range->mark_range_cnt++;
if (packet->flags.ignored) {
@@ -133,8 +132,8 @@ static void packet_range_calc(packet_range_t *range) {
}
}
- if (current_count >= displayed_mark_low &&
- current_count <= displayed_mark_high)
+ if (framenum >= displayed_mark_low &&
+ framenum <= displayed_mark_high)
{
if (packet->flags.passed_dfilter) {
range->displayed_mark_range_cnt++;
@@ -159,7 +158,7 @@ static void packet_range_calc(packet_range_t *range) {
/* (re-)calculate the user specified packet range counts */
static void packet_range_calc_user(packet_range_t *range) {
- guint32 current_count;
+ guint32 framenum;
frame_data *packet;
range->user_range_cnt = 0L;
@@ -167,11 +166,10 @@ static void packet_range_calc_user(packet_range_t *range) {
range->displayed_user_range_cnt = 0L;
range->displayed_ignored_user_range_cnt = 0L;
- current_count = 0;
- for(packet = cfile.plist_start; packet != NULL; packet = packet->next) {
- current_count++;
+ for(framenum = 1; framenum <= cfile.count; framenum++) {
+ packet = cap_file_find_fdata(&cfile, framenum);
- if (value_is_in_range(range->user_range, current_count)) {
+ if (value_is_in_range(range->user_range, framenum)) {
range->user_range_cnt++;
if (packet->flags.ignored) {
range->ignored_user_range_cnt++;