Skip to content

Commit

Permalink
Freeze global proc IDs and pathToType
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 committed Oct 15, 2024
1 parent 4ab72b6 commit 9ee8585
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions OpenDreamRuntime/Objects/DreamObjectTree.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -47,8 +48,8 @@ public sealed class DreamObjectTree {
public TreeEntry Obj { get; private set; }
public TreeEntry Mob { get; private set; }

private readonly Dictionary<string, TreeEntry> _pathToType = new();
private Dictionary<string, int> _globalProcIds;
private FrozenDictionary<string, TreeEntry> _pathToType = FrozenDictionary<string, TreeEntry>.Empty;
private FrozenDictionary<string, int> _globalProcIds = FrozenDictionary<string, int>.Empty;

[Dependency] private readonly AtomManager _atomManager = default!;
[Dependency] private readonly DreamManager _dreamManager = default!;
Expand Down Expand Up @@ -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<string, TreeEntry>(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");
Expand Down Expand Up @@ -426,13 +430,15 @@ private void LoadProcsFromJson(ProcDefinitionJson[]? jsonProcs, int[]? jsonGloba
}

if (jsonGlobalProcs != null) {
_globalProcIds = new(jsonGlobalProcs.Length);
Dictionary<string, int> 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();
}
}

Expand Down

0 comments on commit 9ee8585

Please sign in to comment.