optimize: streaming diff performance (#2150)

This commit is contained in:
yetone
2025-06-04 23:28:28 +08:00
committed by GitHub
parent 16e041ff9a
commit 3a77a591b3
2 changed files with 27 additions and 0 deletions

View File

@@ -1646,4 +1646,20 @@ function M.message_to_text(message, messages)
return ""
end
function M.count_lines(str)
if not str or str == "" then return 0 end
local count = 1
local len = #str
local newline_byte = string.byte("\n")
for i = 1, len do
if str:byte(i) == newline_byte then count = count + 1 end
end
if str:byte(len) == newline_byte then count = count - 1 end
return count
end
return M