From 3424258ac65c8e3f93efa4eeeca3ae4d9c1ac9ed Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 17 Oct 2025 17:14:07 +0200 Subject: [PATCH] added back drop_old_entries as well as a test case for it, only trigger it after a skip --- dap/utils/sorter.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/dap/utils/sorter.py b/dap/utils/sorter.py index 755610b..4a9480f 100644 --- a/dap/utils/sorter.py +++ b/dap/utils/sorter.py @@ -18,7 +18,9 @@ class Sorter: def flush_ready(self): res = self._collect_contiguous_IDs() - self._skip_over_gap() + skipped = self._skip_over_gap() + if skipped: + self._drop_old_entries() return res def _collect_contiguous_IDs(self): @@ -30,7 +32,16 @@ class Sorter: return res def _skip_over_gap(self): - self.next_ID = max(self.next_ID, self.max_ID - self.window) + threshold = self.max_ID - self.window + skip = self.next_ID < threshold + if skip: + self.next_ID = threshold + return skip + + def _drop_old_entries(self): + for i in list(self.buffer): + if i < self.next_ID: + del self.buffer[i] @@ -63,5 +74,28 @@ if __name__ == "__main__": exc = [(i, i) for i in exc] assert exc == ready, f"{exc} != {ready}" + assert sorter.buffer == {} + + + sorter = Sorter(window=5) + + data = [ + 0, # this is sent -- small gap coming + 2, # large gap coming -- this goes stale + ] + list(range(10, 17)) # this is sent + + expected = [ + [0], + [], [], [], [], [], [], [] + ] + [list(range(10, 17))] + + for ID, exc in zip(data, expected): + sorter.add(ID, ID) + ready = sorter.flush_ready() + exc = [(i, i) for i in exc] + assert exc == ready, f"{exc} != {ready}" + + assert sorter.buffer == {} +