Skip to content

Commit

Permalink
perf(compiler): remove require call to write compiled file (#311)
Browse files Browse the repository at this point in the history
pref(compiler): reduce compiled size by aliasing `vim.api.nvim_set_hl`
  • Loading branch information
EdenEast committed Feb 14, 2023
1 parent 5aeb0e7 commit 14489df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lua/nightfox/lib/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function M.compile(opts)
local lines = {
fmt(
[[
require("nightfox").compiled = string.dump(function()
return string.dump(function()
local h = vim.api.nvim_set_hl
if vim.g.colors_name then vim.cmd("hi clear") end
vim.o.termguicolors = true
vim.g.colors_name = "%s"
Expand All @@ -50,13 +51,13 @@ vim.o.background = "%s"

for name, values in pairs(groups) do
if should_link(values.link) then
table.insert(lines, fmt([[vim.api.nvim_set_hl(0, "%s", { link = "%s" })]], name, values.link))
table.insert(lines, fmt([[h(0, "%s", { link = "%s" })]], name, values.link))
else
local op = parse_styles(values.style)
op.bg = values.bg
op.fg = values.fg
op.sp = values.sp
table.insert(lines, fmt([[vim.api.nvim_set_hl(0, "%s", %s)]], name, inspect(op)))
table.insert(lines, fmt([[h(0, "%s", %s)]], name, inspect(op)))
end
end

Expand Down Expand Up @@ -94,8 +95,7 @@ Bellow is the error message:
dofile(tmpfile)
end

f()
file:write(require("nightfox").compiled)
file:write(f())
file:close()
end

Expand Down
5 changes: 2 additions & 3 deletions lua/nightfox/lib/vim/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function M.compile(opts)
local lines = {
fmt(
[[
require("nightfox").compiled = string.dump(function()
return string.dump(function()
vim.command([[
if exists("colors_name")
hi clear
Expand Down Expand Up @@ -91,8 +91,7 @@ Bellow is the error message:
dofile(tmpfile)
end

f()
file:write(require("nightfox").compiled)
file:write(f())
file:close()
end

Expand Down

0 comments on commit 14489df

Please sign in to comment.