From 23a0f6ca796651e122f3e921aea35f6e495e3f65 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Mon, 22 Nov 2021 06:23:16 +0100 Subject: [PATCH] Speed up highlighter notify Avoid calling `table.{insert,remove}` multiple times, as this causes multiple shifts in the `self.lines` table. --- data/core/doc/highlighter.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/data/core/doc/highlighter.lua b/data/core/doc/highlighter.lua index c77e1138..22ed12a4 100644 --- a/data/core/doc/highlighter.lua +++ b/data/core/doc/highlighter.lua @@ -1,4 +1,5 @@ local core = require "core" +local common = require "core.common" local config = require "core.config" local tokenizer = require "core.tokenizer" local Object = require "core.object" @@ -51,16 +52,16 @@ end function Highlighter:insert_notify(line, n) self:invalidate(line) + local blanks = { } for i = 1, n do - table.insert(self.lines, line, false) + blanks[i] = false end + common.splice(self.lines, line, 0, blanks) end function Highlighter:remove_notify(line, n) self:invalidate(line) - for i = 1, n do - table.remove(self.lines, line) - end + common.splice(self.lines, line, n) end