The Free Software Media System - Server Backend & API
Apply suggestions from code review
Matt Montgomery0945659cb572
diff --git a/Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs b/Emby.Server.Implementations/QuickConnect/QuickConnectManager.csindex 263556e9d7..a69ea2267b 100644--- a/Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs+++ b/Emby.Server.Implementations/QuickConnect/QuickConnectManager.cs@@ -149,15 +149,16 @@ namespace Emby.Server.Implementations.QuickConnect/// <inheritdoc/>public string GenerateCode(){+ Span<byte> raw = stackalloc byte[4];+int min = (int)Math.Pow(10, CodeLength - 1);int max = (int)Math.Pow(10, CodeLength);uint scale = uint.MaxValue;while (scale == uint.MaxValue){- byte[] raw = new byte[4];_rng.GetBytes(raw);- scale = BitConverter.ToUInt32(raw, 0);+ scale = BitConverter.ToUInt32(raw);}int code = (int)(min + ((max - min) * (scale / (double)uint.MaxValue)));@@ -247,7 +248,7 @@ namespace Emby.Server.Implementations.QuickConnectprivate string GenerateSecureRandom(int length = 32){- var bytes = new byte[length];+ Span<byte> bytes = stackalloc byte[length];_rng.GetBytes(bytes);return Hex.Encode(bytes);@@ -265,7 +266,7 @@ namespace Emby.Server.Implementations.QuickConnect}// Expire stale connection requests- var delete = new List<string>();+ var code = string.Empty;var values = _currentRequests.Values.ToList();for (int i = 0; i < values.Count; i++)@@ -273,17 +274,13 @@ namespace Emby.Server.Implementations.QuickConnectvar added = values[i].DateAdded ?? DateTime.UnixEpoch;if (DateTime.Now > added.AddMinutes(Timeout) || expireAll){- delete.Add(values[i].Code);- }- }+ code = values[i].Code;+ _logger.LogDebug("Removing expired request {code}", code);- foreach (var code in delete)- {- _logger.LogDebug("Removing expired request {code}", code);-- if (!_currentRequests.TryRemove(code, out _))- {- _logger.LogWarning("Request {code} already expired", code);+ if (!_currentRequests.TryRemove(code, out _))+ {+ _logger.LogWarning("Request {code} already expired", code);+ }}}}diff --git a/MediaBrowser.Api/QuickConnect/QuickConnectService.cs b/MediaBrowser.Api/QuickConnect/QuickConnectService.csindex 9047a1e957..6298f66e59 100644--- a/MediaBrowser.Api/QuickConnect/QuickConnectService.cs+++ b/MediaBrowser.Api/QuickConnect/QuickConnectService.cs@@ -110,7 +110,7 @@ namespace MediaBrowser.Api.QuickConnectpublic object Post(Activate request){- if(_quickConnect.State == QuickConnectState.Unavailable)+ if (_quickConnect.State == QuickConnectState.Unavailable){return false;}