Freeze non-mutable readonly static dictionaries.
Since these will live for the lifetime of the process, it is worth freezing them on creation to improve lookup performance. If the dictionaries were iterated, change to an immutable array instead to preserve the order.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
f4eb5739d6
commit
9e548fd0f0
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -40,7 +41,7 @@ namespace OpenRA
|
||||
return GetHashFunction(sync)(sync);
|
||||
}
|
||||
|
||||
static readonly Dictionary<Type, MethodInfo> CustomHashFunctions = new()
|
||||
static readonly FrozenDictionary<Type, MethodInfo> CustomHashFunctions = new Dictionary<Type, MethodInfo>
|
||||
{
|
||||
{ typeof(int2), ((Func<int2, int>)HashInt2).Method },
|
||||
{ typeof(CPos), ((Func<CPos, int>)HashCPos).Method },
|
||||
@@ -53,7 +54,7 @@ namespace OpenRA
|
||||
{ typeof(Actor), ((Func<Actor, int>)HashActor).Method },
|
||||
{ typeof(Player), ((Func<Player, int>)HashPlayer).Method },
|
||||
{ typeof(Target), ((Func<Target, int>)HashTarget).Method },
|
||||
};
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
static void EmitSyncOpcodes(Type type, ILGenerator il)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user