Skip to content

Commit 21c2a7f

Browse files
authored
Optimizes BuildIncludesTable to not lagspike if you have 100 tabs open (#2031)
* Optimizes BuildIncludesTable to not lagspike if you have 100 tabs open * ws
1 parent f3b2828 commit 21c2a7f

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

lua/starfall/editor/editor.lua

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,6 @@ if CLIENT then
145145
end
146146
end
147147

148-
function SF.Editor.getOpenFiles()
149-
local files = {}
150-
for i = 1, SF.Editor.editor:GetNumTabs() do
151-
local tab = SF.Editor.editor:GetTabContent(i)
152-
local path = tab.chosenfile
153-
if path and tab.GetCode then
154-
if SF.Editor.editor:ShouldReloadBeforeUpload() then
155-
SF.Editor.editor:ReloadTabs(false)
156-
end
157-
files[path:match("starfall/(.+)") or path] = tab:GetCode()
158-
end
159-
end
160-
return files
161-
end
162-
163148
function SF.Editor.createEditor()
164149
local editor = vgui.Create("StarfallEditorFrame") --Should define own frame later
165150

@@ -212,8 +197,21 @@ if CLIENT then
212197
function SF.Editor.BuildIncludesTable(mainfile, success, err)
213198
if not SF.Editor.initialized then SF.Editor.init() end
214199

215-
local openfiles = SF.Editor.getOpenFiles()
216-
if not (mainfile and (openfiles[mainfile] or file.Exists("starfall/" .. mainfile, "DATA"))) then
200+
local opentabs = {}
201+
for i = 1, SF.Editor.editor:GetNumTabs() do
202+
local tab = SF.Editor.editor:GetTabContent(i)
203+
local path = tab.chosenfile
204+
if path and tab.GetCode then
205+
if SF.Editor.editor:ShouldReloadBeforeUpload() then
206+
SF.Editor.editor:ReloadTab(i, false)
207+
end
208+
opentabs[string.match(path, "starfall/(.+)") or path] = tab
209+
end
210+
end
211+
212+
local openfiles = setmetatable({},{__index = function(t,k) if opentabs[k] then local r=opentabs[k]:GetCode() t[k]=r return r end end})
213+
214+
if not (mainfile and (opentabs[mainfile] or file.Exists("starfall/" .. mainfile, "DATA"))) then
217215
mainfile = SF.Editor.getOpenFile() or "main"
218216
if #mainfile == 0 then err("Invalid main file") return end
219217
openfiles[mainfile] = SF.Editor.getCode()

0 commit comments

Comments
 (0)