Skip to content

Commit

Permalink
Improve performance with CharacterOptionExtensions
Browse files Browse the repository at this point in the history
There is some overhead with calling GetAttributeOfType, so we are pre-caching these results.
  • Loading branch information
FlaggAC committed Jul 24, 2024
1 parent 8e37308 commit 24abd8f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/ACE.Entity/Enum/CharacterOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,24 @@ public enum CharacterOption

public static class CharacterOptionExtensions
{
private static Dictionary<CharacterOption, CharacterOptions1Attribute> CharacterOptions1Attributes { get; }
private static Dictionary<CharacterOption, CharacterOptions2Attribute> CharacterOptions2Attributes { get; }

static CharacterOptionExtensions()
{
var vals = System.Enum.GetValues(typeof(CharacterOption)).Cast<CharacterOption>();
CharacterOptions1Attributes = vals.ToDictionary(o => o, o => o.GetAttributeOfType<CharacterOptions1Attribute>());
CharacterOptions2Attributes = vals.ToDictionary(o => o, o => o.GetAttributeOfType<CharacterOptions2Attribute>());
}

public static CharacterOptions1Attribute GetCharacterOptions1Attribute(this CharacterOption val)
{
return val.GetAttributeOfType<CharacterOptions1Attribute>();
return CharacterOptions1Attributes[val];
}

public static CharacterOptions2Attribute GetCharacterOptions2Attribute(this CharacterOption val)
{
return val.GetAttributeOfType<CharacterOptions2Attribute>();
return CharacterOptions2Attributes[val];
}

public static uint GetCharacterOptions1Flag(this ReadOnlyDictionary<CharacterOption, bool> options)
Expand Down

0 comments on commit 24abd8f

Please sign in to comment.