Skip to content

Commit

Permalink
Fully parallelize emoji match searching
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Mar 7, 2023
1 parent 83680e4 commit ce19f7d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,18 +786,20 @@ private void DrawEmojiMessage(List<SKBitmap> sectionImages, List<(Point, TwitchE
while (enumerator.MoveNext())
{
List<SingleEmoji> emojiMatches = new List<SingleEmoji>();
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;
Expand Down Expand Up @@ -842,7 +844,7 @@ private void DrawEmojiMessage(List<SKBitmap> sectionImages, List<(Point, TwitchE
}
else
{
nonEmojiBuffer.Append((string)enumerator.Current);
nonEmojiBuffer.Append(enumerator.GetTextElement());
}
}
if (nonEmojiBuffer.Length > 0)
Expand Down

0 comments on commit ce19f7d

Please sign in to comment.