From b3e32bdbea5f3d434fbc1eddfbd1b9ae8e0fa557 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Sun, 5 Dec 2021 11:05:24 +0100 Subject: [PATCH] Make log.contents() a generator --- picard/log.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/picard/log.py b/picard/log.py index 90e6c19fe..b5595fa69 100644 --- a/picard/log.py +++ b/picard/log.py @@ -119,17 +119,15 @@ class TailLogger(QtCore.QObject): def contents(self, prev=-1): with self._queue_lock: - # If log queue is empty, return - if not self._log_queue: - return [] - offset, length = _calculate_bounds(prev, self._log_queue[0].pos, self._log_queue[-1].pos, len(self._log_queue)) + if self._log_queue: + offset, length = _calculate_bounds(prev, self._log_queue[0].pos, self._log_queue[-1].pos, len(self._log_queue)) - if offset >= 0: - return (self._log_queue[i] for i in range(offset, length)) - # If offset < 0, there is a discontinuity in the queue positions - # Use a slower approach to get the new content. - else: - return (x for x in self._log_queue if x.pos > prev) + if offset >= 0: + yield from (self._log_queue[i] for i in range(offset, length)) + # If offset < 0, there is a discontinuity in the queue positions + # Use a slower approach to get the new content. + else: + yield from (x for x in self._log_queue if x.pos > prev) def clear(self): with self._queue_lock: