mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Reduce allocations when escaping emoji
This commit is contained in:
parent
c47ae99805
commit
98e0b95635
1 changed files with 15 additions and 6 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <QProcessEnvironment>
|
||||
#include <QScreen>
|
||||
#include <QSettings>
|
||||
#include <QStringBuilder>
|
||||
#include <QTextDocument>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
|
@ -66,7 +67,8 @@ utils::codepointIsEmoji(uint code)
|
|||
QString
|
||||
utils::replaceEmoji(const QString &body)
|
||||
{
|
||||
QString fmtBody = "";
|
||||
QString fmtBody;
|
||||
fmtBody.reserve(body.size());
|
||||
|
||||
QVector<uint> utf32_string = body.toUcs4();
|
||||
|
||||
|
@ -74,21 +76,28 @@ utils::replaceEmoji(const QString &body)
|
|||
for (auto &code : utf32_string) {
|
||||
if (utils::codepointIsEmoji(code)) {
|
||||
if (!insideFontBlock) {
|
||||
fmtBody += QString("<font face=\"" +
|
||||
UserSettings::instance()->emojiFont() + "\">");
|
||||
fmtBody += QStringLiteral("<font face=\"") %
|
||||
UserSettings::instance()->emojiFont() %
|
||||
QStringLiteral("\">");
|
||||
insideFontBlock = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (insideFontBlock) {
|
||||
fmtBody += "</font>";
|
||||
fmtBody += QStringLiteral("</font>");
|
||||
insideFontBlock = false;
|
||||
}
|
||||
}
|
||||
fmtBody += QString::fromUcs4(&code, 1);
|
||||
if (QChar::requiresSurrogates(code)) {
|
||||
QChar emoji[] = {static_cast<ushort>(QChar::highSurrogate(code)),
|
||||
static_cast<ushort>(QChar::lowSurrogate(code))};
|
||||
fmtBody.append(emoji, 2);
|
||||
} else {
|
||||
fmtBody.append(QChar(static_cast<ushort>(code)));
|
||||
}
|
||||
}
|
||||
if (insideFontBlock) {
|
||||
fmtBody += "</font>";
|
||||
fmtBody += QStringLiteral("</font>");
|
||||
}
|
||||
|
||||
return fmtBody;
|
||||
|
|
Loading…
Reference in a new issue