Skip to content

Commit

Permalink
PlayerState: optimize GetOption()
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperblast committed Sep 11, 2024
1 parent 3dce2bd commit 27b96e3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Client/PlayerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ public sealed class PlayerState
/// <exception cref="KeyNotFoundException">No option with <paramref name="id"/> was found.</exception>
public PlayerOption GetOption(string id)
{
return Options.FirstOrDefault(o => string.Equals(o.Id, id, StringComparison.OrdinalIgnoreCase))
?? throw new KeyNotFoundException($"Option with id '{id}' is not found.");
PlayerOption? result = null;

foreach (var option in Options)
{
if (string.Equals(option.Id, id, StringComparison.OrdinalIgnoreCase))
{
result = option;
break;
}
}

return result ?? throw new KeyNotFoundException($"Option with id '{id}' is not found.");
}
}

0 comments on commit 27b96e3

Please sign in to comment.