From e469e5507c999fb5a346694d0449ed0e53d0b275 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 25 Oct 2019 17:41:50 -0400 Subject: [PATCH] source.ctf.lttng-live: clean-up: don't restart stream iteration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Don't restart the iteration on a stream array when a stream has to be removed. The contents of the array's current position are replaced by the contents of the last position in the array. Thus, we can continue the iteration from the current index. Signed-off-by: Jérémie Galarneau Change-Id: Ia465f2995d6ee0ad1241063bc62e92cbf40745eb Reviewed-on: https://review.lttng.org/c/babeltrace/+/2263 CI-Build: Simon Marchi Tested-by: jenkins Reviewed-by: Simon Marchi --- src/plugins/ctf/lttng-live/lttng-live.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index e9007acb..7da40dc2 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -955,16 +955,6 @@ enum lttng_live_iterator_status next_stream_iterator_for_trace( g_ptr_array_index(live_trace->stream_iterators, stream_iter_idx); - /* - * Since we may remove elements from the GPtrArray as we - * iterate over it, it's possible to see the same element more - * than once. - */ - if (stream_iter == youngest_candidate_stream_iter) { - stream_iter_idx++; - continue; - } - /* * Find if there is are now current message for this stream * iterator get it. @@ -1067,14 +1057,17 @@ enum lttng_live_iterator_status next_stream_iterator_for_trace( stream_iter_idx++; } else { /* - * The live stream iterator is ENDed. We remove that - * iterator from the list and we restart the iteration - * at the beginning of the live stream iterator array - * to because the removal will shuffle the array. + * The live stream iterator has ended. That + * iterator is removed from the array, but + * there is no need to increment + * stream_iter_idx as + * g_ptr_array_remove_index_fast replaces the + * removed element with the array's last + * element. */ - g_ptr_array_remove_index_fast(live_trace->stream_iterators, + g_ptr_array_remove_index_fast( + live_trace->stream_iterators, stream_iter_idx); - stream_iter_idx = 0; } } -- 2.34.1