Skip to content

latex pattern for raw table treatment is checked twice in Lua : perf improvement ? #11915

@cderv

Description

@cderv

I just noticed this while reading code.

For raw LaTeX Table, we do process table patterns, only when found

elseif hasRawLatexTable(raw) then
for i,pattern in ipairs(_quarto.patterns.latexTablePatterns) do
local match_fun = _quarto.modules.patterns.match_all_in_table(pattern)
if match_fun(raw.text) then
local combined_pattern = _quarto.modules.patterns.combine_patterns(pattern)
raw.text = applyLatexTableCaption(raw.text, tblCaptions[idx], tblLabels[idx], combined_pattern)
break
end
end
idx = idx + 1
elseif hasPagedHtmlTable(raw) then

though we also do the exact same inside the function call

function applyLatexTableCaption(latex, tblCaption, tblLabel, tablePattern)
local latexCaptionPattern = _quarto.patterns.latexCaptionPattern
local latex_caption_match = _quarto.modules.patterns.match_all_in_table(latexCaptionPattern)
-- insert caption if there is none
local beginCaption, caption = latex_caption_match(latex)
if not beginCaption then
latex = latex:gsub(tablePattern, "%1" .. "\n\\caption{ }\\tabularnewline\n" .. "%2%3", 1)
end
-- apply table caption and label
local beginCaption, captionText, endCaption = latex_caption_match(latex)
if #tblCaption > 0 then
captionText = stringEscape(tblCaption, "latex")
end
if #tblLabel > 0 then
captionText = captionText .. " {#" .. tblLabel .. "}"
end
assert(captionText)
latex = latex:gsub(_quarto.modules.patterns.combine_patterns(latexCaptionPattern), "%1" .. captionText:gsub("%%", "%%%%") .. "%3", 1)
return latex
end

As those string matching were already a problem related to perf (#9733), maybe this is worth simplifying here to avoid the duplicate treatment

Metadata

Metadata

Assignees

No one assigned

    Labels

    crossrefenhancementNew feature or requestluaIssues related to the lua codebase, filter chain, etcmaintenanceperformancetablesIssues with Tables including the gt integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions