Fix crash in emoji suggestions.

Fixes #6636.
This commit is contained in:
John Preston 2019-10-03 10:02:28 +03:00
parent af818b40aa
commit 606a90a4ac
1 changed files with 11 additions and 2 deletions

View File

@ -168,11 +168,20 @@ void AppendFoundEmoji(
std::vector<Result> &result,
const QString &label,
const std::vector<LangPackEmoji> &list) {
// It is important that the 'result' won't relocate while inserting.
result.reserve(result.size() + list.size());
const auto alreadyBegin = result.data();
const auto alreadyEnd = alreadyBegin + result.size();
auto &&add = ranges::view::all(
list
) | ranges::view::filter([&](const LangPackEmoji &entry) {
const auto i = ranges::find(result, entry.emoji, &Result::emoji);
return (i == end(result));
const auto i = ranges::find(
alreadyBegin,
alreadyEnd,
entry.emoji,
&Result::emoji);
return (i == alreadyEnd);
}) | ranges::view::transform([&](const LangPackEmoji &entry) {
return Result{ entry.emoji, label, entry.text };
});