diff --git a/OpenDreamRuntime/Objects/DreamObjectTree.cs b/OpenDreamRuntime/Objects/DreamObjectTree.cs index f2492129f4..85d1f59f95 100644 --- a/OpenDreamRuntime/Objects/DreamObjectTree.cs +++ b/OpenDreamRuntime/Objects/DreamObjectTree.cs @@ -1,3 +1,4 @@ +using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Threading.Tasks; @@ -47,8 +48,8 @@ public sealed class DreamObjectTree { public TreeEntry Obj { get; private set; } public TreeEntry Mob { get; private set; } - private readonly Dictionary _pathToType = new(); - private Dictionary _globalProcIds; + private FrozenDictionary _pathToType = FrozenDictionary.Empty; + private FrozenDictionary _globalProcIds = FrozenDictionary.Empty; [Dependency] private readonly AtomManager _atomManager = default!; [Dependency] private readonly DreamManager _dreamManager = default!; @@ -267,14 +268,17 @@ private void LoadTypesFromJson(DreamTypeJson[] types, ProcDefinitionJson[]? proc //First pass: Create types and set them up for initialization Types[0] = Root; + var pathToType = new Dictionary(types.Length); for (int i = 1; i < Types.Length; i++) { var path = types[i].Path; var type = new TreeEntry(path, i); Types[i] = type; - _pathToType[path] = type; + pathToType[path] = type; } + _pathToType = pathToType.ToFrozenDictionary(); + World = GetTreeEntry("/world"); List = GetTreeEntry("/list"); Client = GetTreeEntry("/client"); @@ -426,13 +430,15 @@ private void LoadProcsFromJson(ProcDefinitionJson[]? jsonProcs, int[]? jsonGloba } if (jsonGlobalProcs != null) { - _globalProcIds = new(jsonGlobalProcs.Length); + Dictionary globalProcIds = new(jsonGlobalProcs.Length); foreach (var procId in jsonGlobalProcs) { var proc = Procs[procId]; - _globalProcIds.Add(proc.Name, procId); + globalProcIds.Add(proc.Name, procId); } + + _globalProcIds = globalProcIds.ToFrozenDictionary(); } }