From 718bf88b9afc02b63889fd0893ddacf6c789ac18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 13 Dec 2021 20:03:32 +0100 Subject: [PATCH] Remove superflous null checks and cache a dictionary lookup. --- OpenRA.Game/Sound/Sound.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 6c8801c2e7..91665e7ed5 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -395,7 +395,7 @@ namespace OpenRA if (currentNotifications.ContainsKey(name)) { var currentNotification = currentNotifications[name]; - if (currentNotification != null && !currentNotification.Complete) + if (!currentNotification.Complete) { if (pool.AllowInterrupt) soundEngine.StopSound(currentNotification); @@ -403,12 +403,16 @@ namespace OpenRA return false; } } - else if (currentSounds.ContainsKey(actorId) && !currentSounds[actorId].Complete) + else if (currentSounds.ContainsKey(actorId)) { - if (pool.AllowInterrupt) - soundEngine.StopSound(currentSounds[actorId]); - else - return false; + var currentSound = currentSounds[actorId]; + if (!currentSound.Complete) + { + if (pool.AllowInterrupt) + soundEngine.StopSound(currentSound); + else + return false; + } } var volume = InternalSoundVolume * volumeModifier * pool.VolumeModifier;