Skip to content

Commit

Permalink
Fix emoji unified/non-qualified version for sending & parsing (Chatte…
Browse files Browse the repository at this point in the history
…rino#4840)

Co-authored-by: nerix <[email protected]>
  • Loading branch information
pajlada and Nerixyz authored Oct 7, 2023
1 parent ab4a0c0 commit 774eaa1
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 111 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Minor: The account switcher is now styled to match your theme. (#4817)
- Minor: Add an invisible resize handle to the bottom of frameless user info popups and reply thread popups. (#4795)
- Minor: The installer now checks for the VC Runtime version and shows more info when it's outdated. (#4847)
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
- Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848)
- Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834)
- Bugfix: Fixed a performance issue when displaying replies to certain messages. (#4807)
Expand Down
117 changes: 117 additions & 0 deletions benchmarks/src/Emojis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,120 @@ static void BM_ShortcodeParsing(benchmark::State &state)
}

BENCHMARK(BM_ShortcodeParsing);

static void BM_EmojiParsing(benchmark::State &state)
{
Emojis emojis;

emojis.load();

struct TestCase {
QString input;
std::vector<boost::variant<EmotePtr, QString>> expectedOutput;
};

const auto &emojiMap = emojis.getEmojis();
std::shared_ptr<EmojiData> penguin;
emojiMap.tryGet("1F427", penguin);
auto penguinEmoji = penguin->emote;

std::vector<TestCase> tests{
{
// 1 emoji
"foo 🐧 bar",
// expected output
{
"foo ",
penguinEmoji,
" bar",
},
},
{
// no emoji
"foo bar",
// expected output
{
"foo bar",
},
},
{
// many emoji
"foo 🐧 bar 🐧🐧🐧🐧🐧",
// expected output
{
"foo ",
penguinEmoji,
" bar ",
penguinEmoji,
penguinEmoji,
penguinEmoji,
penguinEmoji,
penguinEmoji,
},
},
};

for (auto _ : state)
{
for (const auto &test : tests)
{
auto output = emojis.parse(test.input);

bool areEqual = std::equal(output.begin(), output.end(),
test.expectedOutput.begin());

if (!areEqual)
{
qDebug() << "BAD BENCH";
for (const auto &v : output)
{
if (v.type() == typeid(QString))
{
qDebug() << "output:" << boost::get<QString>(v);
}
}
}
}
}
}

BENCHMARK(BM_EmojiParsing);

template <class... Args>
static void BM_EmojiParsing2(benchmark::State &state, Args &&...args)
{
Emojis emojis;

emojis.load();

auto argsTuple = std::make_tuple(std::move(args)...);
auto input = std::get<0>(argsTuple);
auto expectedNumEmojis = std::get<1>(argsTuple);
for (auto _ : state)
{
auto output = emojis.parse(input);
int actualNumEmojis = 0;
for (const auto &part : output)
{
if (part.type() == typeid(EmotePtr))
{
++actualNumEmojis;
}
}

if (actualNumEmojis != expectedNumEmojis)
{
qDebug() << "BAD BENCH, EXPECTED NUM EMOJIS IS WRONG"
<< actualNumEmojis;
}
}
}

BENCHMARK_CAPTURE(BM_EmojiParsing2, one_emoji, "foo 🐧 bar", 1);
BENCHMARK_CAPTURE(BM_EmojiParsing2, two_emoji, "foo 🐧 bar 🐧", 2);
BENCHMARK_CAPTURE(
BM_EmojiParsing2, many_emoji,
"πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ "
"πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ "
"πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ πŸ˜‚ ",
61);
Loading

0 comments on commit 774eaa1

Please sign in to comment.