Comparison

util/queue.lua @ 9902:3eea63a68e0f

util.queue: Update :items() to consistently use private data directly It will perform better this way, and we were accessing private variables already within the iterator.
author Matthew Wild <mwild1@gmail.com>
date Sat, 23 Mar 2019 08:52:57 +0000
parent 9901:c8b75239846c
child 9925:8d0112413997
comparison
equal deleted inserted replaced
9901:c8b75239846c 9902:3eea63a68e0f
50 return nil; 50 return nil;
51 end 51 end
52 return t[tail]; 52 return t[tail];
53 end; 53 end;
54 items = function (self) 54 items = function (self)
55 --luacheck: ignore 431/t 55 return function (_, pos)
56 return function (t, pos) 56 if pos >= items then
57 if pos >= t:count() then
58 return nil; 57 return nil;
59 end 58 end
60 local read_pos = tail + pos; 59 local read_pos = tail + pos;
61 if read_pos > t.size then 60 if read_pos > self.size then
62 read_pos = (read_pos%size); 61 read_pos = (read_pos%size);
63 end 62 end
64 return pos+1, t._items[read_pos]; 63 return pos+1, t[read_pos];
65 end, self, 0; 64 end, self, 0;
66 end; 65 end;
67 consume = function (self) 66 consume = function (self)
68 return self.pop, self; 67 return self.pop, self;
69 end; 68 end;