Skip to content

Commit 6b3f905

Browse files
committed
Return parallel arrays from inline_options.get_issues_and_affecting_options
This reduces memory usage, getting rid of many tiny 2-item arrays.
1 parent b9ba809 commit 6b3f905

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/luacheck/filter.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ local function annotate_file_report_with_affecting_options(file_report, option_s
429429
end
430430

431431
local events, per_line_opts = inline_options.validate_options(file_report.events, file_report.per_line_options, stds)
432-
local issues_with_inline_opts = inline_options.get_issues_and_affecting_options(events, per_line_opts)
432+
local issues, inline_option_arrays = inline_options.get_issues_and_affecting_options(events, per_line_opts)
433433

434434
local res = {
435435
issues = {},
436436
options = {}
437437
}
438438

439-
for i, pair in ipairs(issues_with_inline_opts) do
440-
local issue, inline_opts = pair[1], pair[2]
439+
for i, issue in ipairs(issues) do
440+
local inline_opts = inline_option_arrays[i]
441441
local normalized_opts = caching_opts_normalizer:normalize_options(option_stack, inline_opts)
442442
res.issues[i] = issue
443443
res.options[i] = normalized_opts

src/luacheck/inline_options.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,13 @@ end
373373

374374
-- Takes an array of events and a map of per-line options as returned from
375375
-- `get_events()`, possibly with location information stripped from push/pop events.
376-
-- Returns an array of pairs {issue, option_attay} that matches each
377-
-- warning or error with an array of inline option tables that affect it.
376+
-- Returns two parallel arrays, one with issues, one with option table arrays for the issues.
378377
-- Some option arrays may share identity.
379-
-- Returned array is sorted by warning location.
380378
function inline_options.get_issues_and_affecting_options(events, per_line_opts)
381379
local pushes = utils.Stack()
382380
local option_stack = utils.Stack()
383-
local res = {}
381+
local issues = {}
382+
local option_arrays = {}
384383
local empty_option_array = {}
385384

386385
for _, event in ipairs(events) do
@@ -406,7 +405,8 @@ function inline_options.get_issues_and_affecting_options(events, per_line_opts)
406405
option_array = utils.concat_arrays({option_array, line_options})
407406
end
408407

409-
table.insert(res, {event, option_array})
408+
table.insert(issues, event)
409+
table.insert(option_arrays, option_array)
410410
elseif event.options then
411411
option_stack:push(event.options)
412412
elseif event.push then
@@ -423,7 +423,7 @@ function inline_options.get_issues_and_affecting_options(events, per_line_opts)
423423
end
424424
end
425425

426-
return res
426+
return issues, option_arrays
427427
end
428428

429429
-- Extract only warnings and errors from an array of events.

0 commit comments

Comments
 (0)