diff options
| author | Bond_009 <bond.009@outlook.com> | 2022-02-21 14:15:09 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2022-02-21 14:15:09 +0100 |
| commit | f50a250cd9fac47bcbd9a05e99c8ffe4d294e320 (patch) | |
| tree | b205dccb83ad385b0ac338b00680aa4f97fe9b97 /Emby.Dlna | |
| parent | bbac59c6d627ef3ef67e26b10d6571cd9a260466 (diff) | |
Optimize Guid comparisons
* Use Guid.Equals(Guid) instead of the == override
* Ban the usage of Guid.Equals(Object) to prevent accidental boxing
* Compare to default(Guid) instead of Guid.Empty
Diffstat (limited to 'Emby.Dlna')
| -rw-r--r-- | Emby.Dlna/Didl/DidlBuilder.cs | 4 | ||||
| -rw-r--r-- | Emby.Dlna/PlayTo/PlayToController.cs | 24 |
2 files changed, 18 insertions, 10 deletions
diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs index 6803b3b875..6ab5843c15 100644 --- a/Emby.Dlna/Didl/DidlBuilder.cs +++ b/Emby.Dlna/Didl/DidlBuilder.cs @@ -160,7 +160,7 @@ namespace Emby.Dlna.Didl else { var parent = item.DisplayParentId; - if (!parent.Equals(Guid.Empty)) + if (!parent.Equals(default)) { writer.WriteAttributeString("parentID", GetClientId(parent, null)); } @@ -657,7 +657,7 @@ namespace Emby.Dlna.Didl else { var parent = folder.DisplayParentId; - if (parent.Equals(Guid.Empty)) + if (parent.Equals(default)) { writer.WriteAttributeString("parentID", "0"); } diff --git a/Emby.Dlna/PlayTo/PlayToController.cs b/Emby.Dlna/PlayTo/PlayToController.cs index e147cb977e..641701e7b5 100644 --- a/Emby.Dlna/PlayTo/PlayToController.cs +++ b/Emby.Dlna/PlayTo/PlayToController.cs @@ -174,7 +174,7 @@ namespace Emby.Dlna.PlayTo await _sessionManager.OnPlaybackStart(newItemProgress).ConfigureAwait(false); // Send a message to the DLNA device to notify what is the next track in the playlist. - var currentItemIndex = _playlist.FindIndex(item => item.StreamInfo.ItemId == streamInfo.ItemId); + var currentItemIndex = _playlist.FindIndex(item => item.StreamInfo.ItemId.Equals(streamInfo.ItemId)); if (currentItemIndex >= 0) { _currentPlaylistIndex = currentItemIndex; @@ -349,7 +349,9 @@ namespace Emby.Dlna.PlayTo { _logger.LogDebug("{0} - Received PlayRequest: {1}", _session.DeviceName, command.PlayCommand); - var user = command.ControllingUserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(command.ControllingUserId); + var user = command.ControllingUserId.Equals(default) + ? null : + _userManager.GetUserById(command.ControllingUserId); var items = new List<BaseItem>(); foreach (var id in command.ItemIds) @@ -392,7 +394,7 @@ namespace Emby.Dlna.PlayTo _playlist.AddRange(playlist); } - if (!command.ControllingUserId.Equals(Guid.Empty)) + if (!command.ControllingUserId.Equals(default)) { _sessionManager.LogSessionActivity( _session.Client, @@ -446,7 +448,9 @@ namespace Emby.Dlna.PlayTo if (info.Item != null && !EnableClientSideSeek(info)) { - var user = !_session.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(_session.UserId) : null; + var user = _session.UserId.Equals(default) + ? null + : _userManager.GetUserById(_session.UserId); var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, info.SubtitleStreamIndex); await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false); @@ -764,7 +768,9 @@ namespace Emby.Dlna.PlayTo { var newPosition = GetProgressPositionTicks(info) ?? 0; - var user = !_session.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(_session.UserId) : null; + var user = _session.UserId.Equals(default) + ? null + : _userManager.GetUserById(_session.UserId); var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, newIndex, info.SubtitleStreamIndex); await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false); @@ -793,7 +799,9 @@ namespace Emby.Dlna.PlayTo { var newPosition = GetProgressPositionTicks(info) ?? 0; - var user = !_session.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(_session.UserId) : null; + var user = _session.UserId.Equals(default) + ? null + : _userManager.GetUserById(_session.UserId); var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, newIndex); await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false); @@ -949,7 +957,7 @@ namespace Emby.Dlna.PlayTo } } - return Guid.Empty; + return default; } public static StreamParams ParseFromUrl(string url, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager) @@ -964,7 +972,7 @@ namespace Emby.Dlna.PlayTo ItemId = GetItemId(url) }; - if (request.ItemId.Equals(Guid.Empty)) + if (request.ItemId.Equals(default)) { return request; } |
