From 0fd6b0c8524912ec9cc4b98cae03434a9db1154c Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 15 Oct 2019 00:55:33 +0300 Subject: [PATCH] Use linq expression to count deleted comments --- osu.Game/Online/API/Requests/Responses/Comment.cs | 14 +------------- osu.Game/Overlays/Comments/CommentsContainer.cs | 9 ++------- osu.Game/Overlays/Comments/DrawableComment.cs | 2 +- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/osu.Game/Online/API/Requests/Responses/Comment.cs b/osu.Game/Online/API/Requests/Responses/Comment.cs index 9e8f0cada2..046de194db 100644 --- a/osu.Game/Online/API/Requests/Responses/Comment.cs +++ b/osu.Game/Online/API/Requests/Responses/Comment.cs @@ -78,18 +78,6 @@ namespace osu.Game.Online.API.Requests.Responses return WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty)); } - public int GetDeletedChildrenCount() - { - int count = 0; - - if (ChildComments.Any()) - ChildComments.ForEach(child => - { - if (child.IsDeleted) - count++; - }); - - return count; - } + public int GetDeletedChildrenCount => ChildComments.Select(c => c.IsDeleted).Where(c => c).Count(); } } diff --git a/osu.Game/Overlays/Comments/CommentsContainer.cs b/osu.Game/Overlays/Comments/CommentsContainer.cs index 48b3952093..318422bedb 100644 --- a/osu.Game/Overlays/Comments/CommentsContainer.cs +++ b/osu.Game/Overlays/Comments/CommentsContainer.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Online.API.Requests.Responses; using System.Threading; +using System.Linq; namespace osu.Game.Overlays.Comments { @@ -162,13 +163,7 @@ namespace osu.Game.Overlays.Comments { content.Add(loaded); - int deletedComments = 0; - - response.Comments.ForEach(comment => - { - if (comment.IsDeleted && comment.IsTopLevel) - deletedComments++; - }); + int deletedComments = response.Comments.Select(c => c.IsDeleted && c.IsTopLevel).Where(c => c).Count(); deletedChildrenPlaceholder.DeletedCount.Value = initial ? deletedComments : deletedChildrenPlaceholder.DeletedCount.Value + deletedComments; diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index 81a6c6a743..13c67b9f5b 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -180,7 +180,7 @@ namespace osu.Game.Overlays.Comments } }; - deletedChildrenPlaceholder.DeletedCount.Value = comment.GetDeletedChildrenCount(); + deletedChildrenPlaceholder.DeletedCount.Value = comment.GetDeletedChildrenCount; if (comment.UserId.HasValue) username.AddUserLink(comment.User);