110
110
function batched_command_utils .sort_batch (driver , batch )
111
111
local sorted_batch = KVCounter ()
112
112
local misfits = {}
113
- local to_match_table = {}
114
113
115
114
for _ , to_inspect in ipairs (batch ) do
116
115
-- Check if we can handle this in a batch
@@ -152,9 +151,10 @@ function batched_command_utils.sort_batch(driver, batch)
152
151
local index = # by_command + 1
153
152
-- Finally, group commands with matching bridge and command name by matching arguments
154
153
-- and auxilary command data.
155
- for match_idx , _ in ipairs (by_command ) do
154
+ for match_idx , matching_table in ipairs (by_command ) do
156
155
-- Grab first command, all the arguments in this table are the same so it doesn't matter.
157
- local to_match = to_match_table [match_idx ]
156
+ -- next is a defined function on KVCounter that uses a similar implementation as the default Lua next.
157
+ local _ , to_match = matching_table .next (matching_table , nil )
158
158
159
159
if utils .deep_table_eq (to_match .capability_command .args , to_inspect .capability_command .args ) and
160
160
utils .deep_table_eq (to_match .auxilary_command_data , to_inspect .auxilary_command_data ) then
@@ -165,8 +165,6 @@ function batched_command_utils.sort_batch(driver, batch)
165
165
end
166
166
if not by_command [index ] then
167
167
table.insert (by_command , index , KVCounter ())
168
- -- Save this off to grab it easily later
169
- to_match_table [index ] = to_inspect
170
168
end
171
169
by_command [index ][device .id ] = to_inspect
172
170
0 commit comments