Skip to content

Commit

Permalink
Return parallel arrays from inline_options.get_issues_and_affecting_o…
Browse files Browse the repository at this point in the history
…ptions

This reduces memory usage, getting rid of many tiny 2-item arrays.
  • Loading branch information
mpeterv committed Jul 1, 2018
1 parent b9ba809 commit 6b3f905
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/luacheck/filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ local function annotate_file_report_with_affecting_options(file_report, option_s
end

local events, per_line_opts = inline_options.validate_options(file_report.events, file_report.per_line_options, stds)
local issues_with_inline_opts = inline_options.get_issues_and_affecting_options(events, per_line_opts)
local issues, inline_option_arrays = inline_options.get_issues_and_affecting_options(events, per_line_opts)

local res = {
issues = {},
options = {}
}

for i, pair in ipairs(issues_with_inline_opts) do
local issue, inline_opts = pair[1], pair[2]
for i, issue in ipairs(issues) do
local inline_opts = inline_option_arrays[i]
local normalized_opts = caching_opts_normalizer:normalize_options(option_stack, inline_opts)
res.issues[i] = issue
res.options[i] = normalized_opts
Expand Down
12 changes: 6 additions & 6 deletions src/luacheck/inline_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,13 @@ end

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

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

table.insert(res, {event, option_array})
table.insert(issues, event)
table.insert(option_arrays, option_array)
elseif event.options then
option_stack:push(event.options)
elseif event.push then
Expand All @@ -423,7 +423,7 @@ function inline_options.get_issues_and_affecting_options(events, per_line_opts)
end
end

return res
return issues, option_arrays
end

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

0 comments on commit 6b3f905

Please sign in to comment.