Skip to content

Commit

Permalink
Use TryGetValue wherever possible
Browse files Browse the repository at this point in the history
Rider says so.
  • Loading branch information
peppy committed Nov 22, 2024
1 parent 479ff7e commit c844d65
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ public override Drawable GetDrawableComponent(ISkinComponentLookup lookup)

private Drawable getResult(HitResult result)
{
if (!hit_result_mapping.ContainsKey(result))
if (!hit_result_mapping.TryGetValue(result, out var value))
return null;

string filename = this.GetManiaSkinConfig<string>(hit_result_mapping[result])?.Value
string filename = this.GetManiaSkinConfig<string>(value)?.Value
?? default_hit_result_skin_filenames[result];

var animation = this.GetAnimation(filename, true, true, frameLength: 1000 / 20d);
Expand Down
7 changes: 3 additions & 4 deletions osu.Game/Overlays/Chat/ChannelList/ChannelList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ public void AddChannel(Channel channel)

public void RemoveChannel(Channel channel)
{
if (!channelMap.ContainsKey(channel))
if (!channelMap.TryGetValue(channel, out var item))
return;

ChannelListItem item = channelMap[channel];
FillFlowContainer<ChannelListItem> flow = getFlowForChannel(channel);

channelMap.Remove(channel);
Expand All @@ -134,10 +133,10 @@ public void RemoveChannel(Channel channel)

public ChannelListItem GetItem(Channel channel)
{
if (!channelMap.ContainsKey(channel))
if (!channelMap.TryGetValue(channel, out var item))
throw new ArgumentOutOfRangeException();

return channelMap[channel];
return item;
}

public void ScrollChannelIntoView(Channel channel) => scroll.ScrollIntoView(GetItem(channel));
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public void SendStartPlay(int userId, int beatmapId, APIMod[]? mods = null)
/// <param name="state">The spectator state to end play with.</param>
public void SendEndPlay(int userId, SpectatedUserState state = SpectatedUserState.Quit)
{
if (!userBeatmapDictionary.ContainsKey(userId))
if (!userBeatmapDictionary.TryGetValue(userId, out int value))
return;

((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
{
BeatmapID = userBeatmapDictionary[userId],
BeatmapID = value,
RulesetID = 0,
Mods = userModsDictionary[userId],
State = state
Expand Down

0 comments on commit c844d65

Please sign in to comment.