File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed
Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ public virtual ulong[] ReadPrefixedULongs()
140140
141141 public virtual T ReadEnum < T > ( ) where T : Enum
142142 {
143- var values = EnumCache . GetValues ( typeof ( T ) ) ;
143+ var values = EnumCache < T > . Values ;
144144 ushort enumIndex = values . Length switch
145145 {
146146 <= byte . MaxValue => ReadByte ( ) ,
Original file line number Diff line number Diff line change 55using System . Runtime . CompilerServices ;
66using System . Text ;
77using Multiplayer . Common . Util ;
8+ using Verse ;
89
910namespace Multiplayer . Common
1011{
@@ -86,7 +87,7 @@ public virtual ByteWriter WriteString(string? s)
8687
8788 public virtual void WriteEnum < T > ( T value ) where T : Enum
8889 {
89- var values = EnumCache . GetValues ( value . GetType ( ) ) ;
90+ var values = typeof ( T ) == typeof ( Enum ) ? EnumCache . Values ( value . GetType ( ) ) : EnumCache < T > . Values ;
9091 var index = Array . IndexOf ( values , value ) ;
9192 switch ( values . Length )
9293 {
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Concurrent ;
3+ using System . Linq ;
34
45namespace Multiplayer . Common . Util ;
56
7+ internal static class EnumCache < T > where T : Enum
8+ {
9+ public static readonly T [ ] Values = Enum . GetValues ( typeof ( T ) ) . Cast < T > ( ) . ToArray ( ) ;
10+ }
11+
612internal static class EnumCache
713{
814 private static readonly ConcurrentDictionary < Type , Array > Cache = new ( ) ;
915
10- public static Array GetValues ( Type enumType ) => Cache . GetOrAdd ( enumType , Enum . GetValues ) ;
11- }
16+ public static Array Values ( Type enumType ) => Cache . GetOrAdd ( enumType , Enum . GetValues ) ;
17+ }
You can’t perform that action at this time.
0 commit comments