Skip to content

Commit 776d321

Browse files
committed
perf(output): use table directly instead of function call overhead
1 parent 0e7da03 commit 776d321

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

lua/opencode/ui/output.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ end
3434
---@param fit? boolean Optional parameter to control line fitting
3535
---@return number index The index of the added line
3636
function Output:add_line(line, fit)
37-
local win_width = state.windows and vim.api.nvim_win_get_width(state.windows.output_win) or config.ui.window_width
38-
if fit and #line > win_width then
39-
line = vim.fn.strcharpart(line, 0, win_width - 7) .. '...'
40-
end
4137
table.insert(self.lines, line)
4238
return #self.lines
4339
end
@@ -63,22 +59,22 @@ end
6359
---@param prefix? string Optional prefix for each line
6460
function Output:add_lines(lines, prefix)
6561
for _, line in ipairs(lines) do
66-
prefix = prefix or ''
67-
6862
if line == '' then
69-
self:add_empty_line()
63+
table.insert(self.lines, '')
7064
else
71-
self:add_line(prefix .. line)
65+
prefix = prefix or ''
66+
table.insert(self.lines, prefix .. line)
7267
end
7368
end
7469
end
7570

7671
---Add an empty line if the last line is not empty
7772
---@return number? index The index of the added line, or nil if no line was added
7873
function Output:add_empty_line()
79-
local last_line = self.lines[#self.lines]
80-
if not last_line or last_line ~= '' then
81-
return self:add_line('')
74+
local line_count = #self.lines
75+
if line_count == 0 or self.lines[line_count] ~= '' then
76+
table.insert(self.lines, '')
77+
return line_count + 1
8278
end
8379
return nil
8480
end

0 commit comments

Comments
 (0)