Skip to content

Commit 8eaade7

Browse files
Update HookMethod in order to improve performance and reduce allocations
1 parent 7d674f1 commit 8eaade7

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/Plugins/HookMethod.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
3-
using System.Linq;
44
using System.Reflection;
5+
using Oxide.Pooling;
56

67
namespace Oxide.Core.Plugins
78
{
@@ -22,9 +23,26 @@ public HookMethod(MethodInfo method)
2223

2324
Parameters = Method.GetParameters();
2425

25-
if (Parameters.Length > 0)
26+
int parameterCount = Parameters.Length;
27+
if (parameterCount > 0)
2628
{
27-
Name += $"({string.Join(", ", Parameters.Select(x => x.ParameterType.ToString()).ToArray())})";
29+
List<string> parameterNames = PoolFactory<List<string>>.Shared.Take();
30+
try
31+
{
32+
for (int i = 0; i < parameterCount; i++)
33+
{
34+
ParameterInfo parameter = Parameters[i];
35+
string name = parameter.ParameterType.ToString();
36+
parameterNames.Add(name);
37+
}
38+
39+
Name = $"{Name}({parameterNames.JoinValues(", ")})";
40+
}
41+
finally
42+
{
43+
parameterNames.Clear();
44+
PoolFactory<List<string>>.Shared.Return(parameterNames);
45+
}
2846
}
2947

3048
IsBaseHook = Name.StartsWith("base_");

0 commit comments

Comments
 (0)