From 3d5c047843a984b96993b5499abbbdb66c34f85b Mon Sep 17 00:00:00 2001 From: Kaian Date: Wed, 28 Feb 2018 21:29:26 +0100 Subject: [PATCH] vector: fix vector sorter functions everywhere #234 --- src/capture.c | 6 ------ src/curses/ui_call_flow.c | 6 ------ src/group.c | 4 +++- src/sip.c | 7 ------- src/vector.c | 2 +- 5 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/capture.c b/src/capture.c index 893d4e9..638494d 100644 --- a/src/capture.c +++ b/src/capture.c @@ -1059,12 +1059,6 @@ capture_packet_time_sorter(vector_t *vector, void *item) // TODO Implement multiframe packets curts = packet_time(item); - prevts = packet_time(vector_last(vector)); - - // Check if the item is already sorted - if (timeval_is_older(curts, prevts)) { - return; - } for (i = count - 2 ; i >= 0; i--) { // Get previous packet diff --git a/src/curses/ui_call_flow.c b/src/curses/ui_call_flow.c index 9f5dd6f..33549e1 100644 --- a/src/curses/ui_call_flow.c +++ b/src/curses/ui_call_flow.c @@ -1500,12 +1500,6 @@ call_flow_arrow_sorter(vector_t *vector, void *item) return; curts = call_flow_arrow_time(item); - prevts = call_flow_arrow_time(vector_item(vector, vector_count(vector) - 2)); - - // Check if the item is already sorted - if (timeval_is_older(curts, prevts)) { - return; - } for (i = count - 2 ; i >= 0; i--) { // Get previous arrow diff --git a/src/group.c b/src/group.c index bb62563..4874208 100644 --- a/src/group.c +++ b/src/group.c @@ -313,7 +313,6 @@ call_group_msg_sorter(vector_t *vector, void *item) // Current and last packet times curts = msg_get_time(item); - prevts = msg_get_time(vector_last(vector)); for (i = count - 2 ; i >= 0; i--) { // Get previous packet @@ -324,4 +323,7 @@ call_group_msg_sorter(vector_t *vector, void *item) return; } } + + // Put this item at the begining of the vector + vector_insert(vector, item, 0); } diff --git a/src/sip.c b/src/sip.c index 808de4f..8d2c7e7 100644 --- a/src/sip.c +++ b/src/sip.c @@ -933,13 +933,6 @@ sip_list_sorter(vector_t *vector, void *item) if (vector_count(vector) == 1) return; - prev = vector_item(vector, vector_count(vector) - 2); - - // Check if the item is already sorted - if (call_attr_compare(cur, prev, calls.sort.by) == 0) { - return; - } - for (i = count - 2 ; i >= 0; i--) { // Get previous item prev = vector_item(vector, i); diff --git a/src/vector.c b/src/vector.c index 8d778e9..f80842b 100644 --- a/src/vector.c +++ b/src/vector.c @@ -192,7 +192,7 @@ vector_insert(vector_t *vector, void *item, int pos) if (!item) return vector->count; - if (pos < 0 || pos > vector->count) + if (pos < 0 || pos > vector->count - 2) return vector->count; // If position is already filled with that item, we're done