aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-16 12:16:45 +0100
committerKim Alvefur <zash@zash.se>2021-12-16 12:16:45 +0100
commit081647ea1ffaf7bf932e727c9311e765b642da5b (patch)
treede2384b2981bf7c5f94fe5ca3547bb09b86a984e /teal-src
parent81d747b6a48402d86b97442866842e4feffca8b9 (diff)
downloadprosody-081647ea1ffaf7bf932e727c9311e765b642da5b.tar.gz
prosody-081647ea1ffaf7bf932e727c9311e765b642da5b.zip
util.smqueue: Simplify compat table, fix dependent modules (thanks Martin)
There was an off-by-one in the modulo calculation. Switching to a plain old array-table makes the apparent size of the queue wrong, but since some of the queue may not be available this is likely for the best.
Diffstat (limited to 'teal-src')
-rw-r--r--teal-src/util/smqueue.tl21
1 files changed, 6 insertions, 15 deletions
diff --git a/teal-src/util/smqueue.tl b/teal-src/util/smqueue.tl
index 26bebe60..e149dde7 100644
--- a/teal-src/util/smqueue.tl
+++ b/teal-src/util/smqueue.tl
@@ -70,22 +70,13 @@ function smqueue:consume() : queue.queue.consume_iter
return self._queue:consume()
end
--- Compatibility wrapper, meant to look like a plain ol' array
-local record compat_mt
- _queue : smqueue<any>
-end
-
-function compat_mt:__index(i : integer) : any
- if i < self._queue._tail then return nil end
- return self._queue._queue._items[(i + self._queue._tail) % self._queue._queue.size];
-end
-
-function compat_mt:__len() : integer
- return self._queue:count_unacked()
-end
-
+-- Compatibility layer, plain ol' table
function smqueue:table() : { any }
- return setmetatable({ _queue = self }, compat_mt);
+ local t : { any } = {};
+ for i, v in self:resume() do
+ t[i] = v;
+ end
+ return t;
end
local function freeze(q : smqueue<any>) : { string:integer }