Skip to content

Commit

Permalink
perf(events): don't deepcopy a table on each new event
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jun 4, 2023
1 parent 0d933c8 commit 12198ef
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lua/neorg/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@ require("neorg.callbacks")

neorg.events = {}

-- Define the base event, all events will derive from this by default
neorg.events.base_event = {

type = "core.base_event",
split_type = {},
content = nil,
referrer = nil,
broadcast = true,

cursor_position = {},
filename = "",
filehead = "",
line_content = "",
buffer = 0,
window = 0,
mode = "",
}

--- The working of this function is best illustrated with an example:
-- If type == 'core.some_plugin.events.my_event', this function will return { 'core.some_plugin', 'my_event' }
---@param type string #The full path of a module event
Expand Down Expand Up @@ -77,7 +59,21 @@ end
function neorg.events.define(module, name)
-- Create a copy of the base event and override the values with ones specified by the user

local new_event = vim.deepcopy(neorg.events.base_event)
local new_event = {
type = "core.base_event",
split_type = {},
content = nil,
referrer = nil,
broadcast = true,

cursor_position = {},
filename = "",
filehead = "",
line_content = "",
buffer = 0,
window = 0,
mode = "",
}

if name then
new_event.type = module.name .. ".events." .. name
Expand Down

0 comments on commit 12198ef

Please sign in to comment.