Mercurial > prosody-hg
comparison util/multitable.lua @ 4895:36df30395c44
util.multitable: No longer use table.remove to drop elements from the stack, when key is nil immediately (on empty tables) the previous stack entry's key gets removed instead
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 19 May 2012 15:35:49 +0100 |
| parents | c874dc4ccbd7 |
| children | 05ea6c1ae393 |
comparison
equal
deleted
inserted
replaced
| 4894:c874dc4ccbd7 | 4895:36df30395c44 |
|---|---|
| 5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
| 7 -- | 7 -- |
| 8 | 8 |
| 9 local select = select; | 9 local select = select; |
| 10 local t_insert, t_remove = table.insert, table.remove; | 10 local t_insert = table.insert; |
| 11 local unpack, pairs, next, type = unpack, pairs, next, type; | 11 local unpack, pairs, next, type = unpack, pairs, next, type; |
| 12 | 12 |
| 13 module "multitable" | 13 module "multitable" |
| 14 | 14 |
| 15 local function get(self, ...) | 15 local function get(self, ...) |
| 133 local keys = { }; | 133 local keys = { }; |
| 134 local function it(self) | 134 local function it(self) |
| 135 local depth = #stack; | 135 local depth = #stack; |
| 136 local key = next(stack[depth], keys[depth]); | 136 local key = next(stack[depth], keys[depth]); |
| 137 if key == nil then -- Go up the stack | 137 if key == nil then -- Go up the stack |
| 138 t_remove(stack); | 138 stack[depth], keys[depth] = nil, nil; |
| 139 t_remove(keys); | |
| 140 if depth > 1 then | 139 if depth > 1 then |
| 141 return it(self); | 140 return it(self); |
| 142 end | 141 end |
| 143 return; -- The end | 142 return; -- The end |
| 144 else | 143 else |
