Speed up highlighter notify

Avoid calling `table.{insert,remove}` multiple times, as this causes 
multiple shifts in the `self.lines` table.
This commit is contained in:
Guldoman 2021-11-22 06:23:16 +01:00
parent a7bbd3d6f7
commit 23a0f6ca79
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
1 changed files with 5 additions and 4 deletions

View File

@ -1,4 +1,5 @@
local core = require "core" local core = require "core"
local common = require "core.common"
local config = require "core.config" local config = require "core.config"
local tokenizer = require "core.tokenizer" local tokenizer = require "core.tokenizer"
local Object = require "core.object" local Object = require "core.object"
@ -51,16 +52,16 @@ end
function Highlighter:insert_notify(line, n) function Highlighter:insert_notify(line, n)
self:invalidate(line) self:invalidate(line)
local blanks = { }
for i = 1, n do for i = 1, n do
table.insert(self.lines, line, false) blanks[i] = false
end end
common.splice(self.lines, line, 0, blanks)
end end
function Highlighter:remove_notify(line, n) function Highlighter:remove_notify(line, n)
self:invalidate(line) self:invalidate(line)
for i = 1, n do common.splice(self.lines, line, n)
table.remove(self.lines, line)
end
end end