-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: store callouts and checkboxes in table keyed on raw value
## Details Currently resolving the callout or checkbox for a particular shortcut_link requires iterating through the configured values one at a time. This is slower than it needs to be since we can pre-compute all the normalized raw values once, store that as the key to the table, then do a single lookup into the table when needed, skipping the for loop. To do this add an additional buffer config type that gets returned from state. This new config will store the normalized component mappings along with all of the other values already present. This will only run once per buffer.
- Loading branch information
1 parent
a5e2d0b
commit 5513e28
Showing
13 changed files
with
54 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
---@class render.md.component.Config | ||
---@field callout table<string, render.md.CustomComponent> | ||
---@field checkbox table<string, render.md.CustomComponent> | ||
|
||
---@class render.md.buffer.Config: render.md.BufferConfig | ||
---@field component render.md.component.Config | ||
|
||
---@class render.md.component.Resolver | ||
local M = {} | ||
|
||
---@param config render.md.BufferConfig | ||
---@return render.md.buffer.Config | ||
function M.resolve(config) | ||
---@type render.md.component.Config | ||
local component = { | ||
callout = M.normalize(config.callout), | ||
checkbox = M.normalize(config.checkbox.custom), | ||
} | ||
return vim.tbl_deep_extend('force', { component = component }, config) | ||
end | ||
|
||
---@private | ||
---@param components table<string, render.md.CustomComponent> | ||
function M.normalize(components) | ||
local result = {} | ||
for _, component in pairs(components) do | ||
result[component.raw:lower()] = component | ||
end | ||
return result | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters