Skip to content

Commit

Permalink
perf: inline function call
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 26, 2024
1 parent cb1c67f commit 71639eb
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lua/indentmini/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,20 @@ ffi.cdef([[
]])

local C = ffi.C
local ml_get_len = C.ml_get_len
local ml_get, ml_get_len = C.ml_get, C.ml_get_len
local find_buffer_by_handle = C.find_buffer_by_handle
local get_sw_value = C.get_sw_value
local get_indent_lnum = C.get_indent_lnum
local ml_get = C.ml_get
local get_sw_value, get_indent_lnum = C.get_sw_value, C.get_indent_lnum
local cache = { snapshot = {} }

local function line_is_empty(lnum)
return tonumber(ml_get_len(lnum)) == 0
end

local function get_shiftw_value(bufnr)
local err = ffi.new('Error')
local handle = find_buffer_by_handle(bufnr, err)
local handle = find_buffer_by_handle(bufnr, ffi.new('Error'))
return get_sw_value(handle)
end

local function get_indent(lnum)
return get_indent_lnum(lnum)
end

local function non_or_space(row, col)
local line = ffi.string(ml_get(row + 1))
local text = line:sub(col, col)
Expand All @@ -54,7 +47,7 @@ end

local function find_in_snapshot(lnum)
if not cache.snapshot[lnum] then
cache.snapshot[lnum] = { get_indent(lnum), line_is_empty(lnum) }
cache.snapshot[lnum] = { get_indent_lnum(lnum), line_is_empty(lnum) }
end
return unpack(cache.snapshot[lnum])
end
Expand Down Expand Up @@ -137,7 +130,7 @@ local function on_win(_, winid, bufnr, toprow, botrow)
cache.count = api.nvim_buf_line_count(bufnr)
cache.reg_srow, cache.reg_erow, cache.cur_inlevel = current_line_range(winid, cache.shiftwidth)
for i = toprow, botrow do
cache.snapshot[i + 1] = { get_indent(i + 1), line_is_empty(i + 1) }
cache.snapshot[i + 1] = { get_indent_lnum(i + 1), line_is_empty(i + 1) }
end
end

Expand Down

0 comments on commit 71639eb

Please sign in to comment.