Optimize compile time of emoji data maps
Compiling the two files including the emoji data now doesn't take significantly longer anymore than before. Size of the .text section also drops by more than 1Mb, while runtime or memory cost remains unchanged. There's more that could be done here, but not having to wait minutes for those files to build is worth it on its own already.
This commit is contained in:
committed by
Joshua Goins
parent
d2aa8d672d
commit
9f64457521
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,26 @@
|
||||
// SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
|
||||
#include "emojitones.h"
|
||||
#include "models/emojimodel.h"
|
||||
|
||||
struct {
|
||||
const char8_t *name;
|
||||
const char8_t *escaped_sequence;
|
||||
const char8_t *shortcode;
|
||||
const char8_t *description;
|
||||
} constexpr const tones_data[] = {
|
||||
#include "emojitones_data.h"
|
||||
};
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
QMultiHash<QString, QVariant> EmojiTones::_tones = {
|
||||
#include "emojitones_data.h"
|
||||
};
|
||||
QMultiHash<QString, Emoji> EmojiTones::tones()
|
||||
{
|
||||
static QMultiHash<QString, Emoji> _tones;
|
||||
if (_tones.isEmpty()) {
|
||||
for (const auto &tone : tones_data) {
|
||||
_tones.insert(QString::fromUtf8(tone.name),
|
||||
Emoji(QString::fromUtf8(tone.escaped_sequence), QString::fromUtf8(tone.shortcode), QString::fromUtf8(tone.description)));
|
||||
}
|
||||
}
|
||||
return _tones;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QVariant>
|
||||
#include "models/emojimodel.h"
|
||||
|
||||
#include <QMultiHash>
|
||||
|
||||
/**
|
||||
* @class EmojiTones
|
||||
@@ -15,7 +17,7 @@
|
||||
class EmojiTones
|
||||
{
|
||||
private:
|
||||
static QMultiHash<QString, QVariant> _tones;
|
||||
static QMultiHash<QString, Emoji> tones();
|
||||
|
||||
friend class EmojiModel;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,15 @@
|
||||
#include "customemojimodel.h"
|
||||
#include <KLocalizedString>
|
||||
|
||||
struct {
|
||||
EmojiModel::Category category;
|
||||
const char8_t *escaped_sequence;
|
||||
const char8_t *shortcode;
|
||||
const char8_t *description;
|
||||
} constexpr const emoji_data[] = {
|
||||
#include "emojis.h"
|
||||
};
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
EmojiModel::EmojiModel(QObject *parent)
|
||||
@@ -20,7 +29,10 @@ EmojiModel::EmojiModel(QObject *parent)
|
||||
, m_configGroup(KConfigGroup(m_config, u"Editor"_s))
|
||||
{
|
||||
if (_emojis.isEmpty()) {
|
||||
#include "emojis.h"
|
||||
for (const auto &emoji : emoji_data) {
|
||||
_emojis[emoji.category].push_back(QVariant::fromValue(
|
||||
Emoji(QString::fromUtf8(emoji.escaped_sequence), QString::fromUtf8(emoji.shortcode), QString::fromUtf8(emoji.description))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,12 +151,12 @@ QVariantList EmojiModel::emojis(Category category) const
|
||||
return _emojis[category];
|
||||
}
|
||||
|
||||
QVariantList EmojiModel::tones(const QString &baseEmoji) const
|
||||
QList<Emoji> EmojiModel::tones(const QString &baseEmoji) const
|
||||
{
|
||||
if (baseEmoji.endsWith(u"tone"_s)) {
|
||||
return EmojiTones::_tones.values(baseEmoji.split(u":"_s)[0]);
|
||||
return EmojiTones::tones().values(baseEmoji.split(u":"_s)[0]);
|
||||
}
|
||||
return EmojiTones::_tones.values(baseEmoji);
|
||||
return EmojiTones::tones().values(baseEmoji);
|
||||
}
|
||||
|
||||
QHash<EmojiModel::Category, QVariantList> EmojiModel::_emojis;
|
||||
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
/**
|
||||
* @brief Return a list of emoji tones for the given base emoji.
|
||||
*/
|
||||
Q_INVOKABLE QVariantList tones(const QString &baseEmoji) const;
|
||||
Q_INVOKABLE [[nodiscard]] QList<Emoji> tones(const QString &baseEmoji) const;
|
||||
|
||||
/**
|
||||
* @brief Return a list of the last used emoji shortnames
|
||||
|
||||
@@ -28,7 +28,7 @@ for (shortcode, props) in gemojione_json.items():
|
||||
|
||||
response = requests.get('https://unicode.org/Public/emoji/14.0/emoji-test.txt')
|
||||
group = ""
|
||||
file = open("../src/emojis.h", "w")
|
||||
file = open("../src/libneochat/emojis.h", "w")
|
||||
# REUSE-IgnoreStart
|
||||
file.write("// SPDX-FileCopyrightText: None\n")
|
||||
file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n")
|
||||
@@ -36,7 +36,7 @@ file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n")
|
||||
file.write("// This file is auto-generated. All changes will be lost. See tools/update-emojis.py\n")
|
||||
file.write("// clang-format off\n")
|
||||
|
||||
tones_file = open("../src/emojitones_data.h", "w")
|
||||
tones_file = open("../src/libneochat/emojitones_data.h", "w")
|
||||
# REUSE-IgnoreStart
|
||||
tones_file.write("// SPDX-FileCopyrightText: None\n")
|
||||
tones_file.write("// SPDX-License-Identifier: LGPL-2.0-or-later\n")
|
||||
@@ -91,12 +91,11 @@ for line in response.text.split("\n"):
|
||||
if escaped_sequence in emoji_unicode_shortname_map:
|
||||
shortcode = emoji_unicode_shortname_map[escaped_sequence]
|
||||
|
||||
emoji_args = 'QString::fromUtf8("{0}"), u"{1}"_s, u"{2}"_s'.format(escaped_sequence, shortcode, description)
|
||||
emoji_qvariant = 'QVariant::fromValue(Emoji{' + emoji_args + '})'
|
||||
emoji_args = 'u8"{0}", u8"{1}", u8"{2}"'.format(escaped_sequence, shortcode, description)
|
||||
|
||||
if is_skin_tone:
|
||||
tones_file.write("{u\"" + description.split(":")[0] + "\"_s, " + emoji_qvariant + "},\n")
|
||||
tones_file.write("{u8\"" + description.split(":")[0] + "\", " + emoji_args + "},\n")
|
||||
continue
|
||||
file.write("_emojis[" + group + "].append(" + emoji_qvariant + ");\n")
|
||||
file.write("{EmojiModel::" + group + ", " + emoji_args + "},\n")
|
||||
file.close()
|
||||
tones_file.close()
|
||||
|
||||
Reference in New Issue
Block a user