From ce19f7d5a71b473671f68d13610237121a29ddf7 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 7 Mar 2023 17:31:39 -0500 Subject: [PATCH] Fully parallelize emoji match searching --- TwitchDownloaderCore/ChatRenderer.cs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index b15ba349..17f92f42 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -786,18 +786,20 @@ private void DrawEmojiMessage(List sectionImages, List<(Point, TwitchE while (enumerator.MoveNext()) { List emojiMatches = new List(); - foreach (var emoji in Emoji.All.AsParallel().Where(emoji => ((string)enumerator.Current).StartsWith(emoji.Sequence.AsString))) - { - if (emoji.Group != "Flags") - { - emojiMatches.Add(emoji); - continue; - } - if (((string)enumerator.Current).StartsWith(emoji.Sequence.AsString, StringComparison.Ordinal)) + Emoji.All.AsParallel() + .Where(emoji => enumerator.GetTextElement().StartsWith(emoji.Sequence.AsString)) + .ForAll(emoji => { - emojiMatches.Add(emoji); - } - } + if (emoji.Group != "Flags") + { + emojiMatches.Add(emoji); + return; + } + if (enumerator.GetTextElement().StartsWith(emoji.Sequence.AsString, StringComparison.Ordinal)) + { + emojiMatches.Add(emoji); + } + }); // Make sure the found emojis actually exist in our cache int emojiMatchesCount = emojiMatches.Count; @@ -842,7 +844,7 @@ private void DrawEmojiMessage(List sectionImages, List<(Point, TwitchE } else { - nonEmojiBuffer.Append((string)enumerator.Current); + nonEmojiBuffer.Append(enumerator.GetTextElement()); } } if (nonEmojiBuffer.Length > 0)