From 93670a314d1c34e4d8f0973b0e159fa976f36e79 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 5 Jun 2021 15:36:26 -0400 Subject: [PATCH] Changed iterator behaviour to avoid allocating a closure each time. --- data/core/doc/init.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 63a4225..21ee3f5 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -169,18 +169,17 @@ function Doc:get_selection_count() end function Doc:get_selections(sort) - local idx = 1 - return function() - if idx >= #self.selections then + return function(selections, idx) + local target = idx*4 + 1 + if target >= #selections then return end - idx = idx + 4 if sort then - return ((idx - 5) / 4) + 1, sort_positions(self.selections[idx - 4], self.selections[idx - 3], self.selections[idx - 2], self.selections[idx - 1]) + return idx+1, sort_positions(selections[target], selections[target+1], selections[target+2], selections[target+3]) else - return ((idx - 5) / 4) + 1, self.selections[idx - 4], self.selections[idx - 3], self.selections[idx - 2], self.selections[idx - 1] + return idx+1, selections[target], selections[target+1], selections[target+2], selections[target+3] end - end + end, self.selections, 0 end