Skip to content

Commit 803f1a2

Browse files
committed
Undo function lookup optimization for now
May cause issues with new functions, code will need to be restructured...
1 parent 2e1763c commit 803f1a2

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

UndertaleModLib/Compiler/CodeBuilder.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ internal class CodeBuilder : ICodeBuilder
1717
// Data being used with this code builder.
1818
private readonly GlobalDecompileContext _globalContext;
1919

20-
// Lookups for variables and functions.
20+
// Lookup for variables.
2121
private readonly Dictionary<(UndertaleString, UndertaleInstruction.InstanceType), UndertaleVariable> _variableLookup;
22-
private readonly Dictionary<string, UndertaleFunction> _functionLookup;
2322

2423
public CodeBuilder(GlobalDecompileContext globalContext)
2524
{
@@ -36,15 +35,6 @@ public CodeBuilder(GlobalDecompileContext globalContext)
3635
}
3736
_variableLookup.TryAdd((v.Name, v.InstanceType), v);
3837
}
39-
IList<UndertaleFunction> functions = _globalContext.Data.Functions;
40-
_functionLookup = new(functions.Count);
41-
foreach (UndertaleFunction f in functions)
42-
{
43-
if (f?.Name?.Content is string name)
44-
{
45-
_functionLookup.TryAdd(name, f);
46-
}
47-
}
4838
}
4939

5040
/// <summary>
@@ -324,31 +314,15 @@ public void PatchInstruction(IGMInstruction instruction, FunctionScope scope, st
324314
}
325315
else if (_globalContext.Builtins.LookupBuiltinFunction(functionName) is not null)
326316
{
327-
if (_functionLookup.TryGetValue(functionName, out UndertaleFunction existingFunction))
328-
{
329-
reference = existingFunction;
330-
}
331-
else
332-
{
333-
reference = _globalContext.Data.Functions.Define(functionName, _globalContext.Data.Strings);
334-
_functionLookup.Add(functionName, reference);
335-
}
317+
reference = _globalContext.Data.Functions.EnsureDefined(functionName, _globalContext.Data.Strings);
336318
}
337319
else if (_globalContext.GlobalFunctions.TryGetFunction(functionName, out IGMFunction function))
338320
{
339321
reference = (UndertaleFunction)function;
340322
}
341323
else if (_globalContext.GetScriptId(functionName, out int _))
342324
{
343-
if (_functionLookup.TryGetValue(functionName, out UndertaleFunction existingFunction))
344-
{
345-
reference = existingFunction;
346-
}
347-
else
348-
{
349-
reference = _globalContext.Data.Functions.Define(functionName, _globalContext.Data.Strings);
350-
_functionLookup.Add(functionName, reference);
351-
}
325+
reference = _globalContext.Data.Functions.EnsureDefined(functionName, _globalContext.Data.Strings);
352326
}
353327
else
354328
{

0 commit comments

Comments
 (0)