mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-21 18:50:47 +03:00
Reduce code bloat a bit
Especially the emoji array shrinks a lot with this, but adds a few extra relocations on startup. But it removes a lot of exception handling code at runtime, which is nice and possibly this is still faster.
This commit is contained in:
parent
20740c9976
commit
920409e914
8 changed files with 11340 additions and 11297 deletions
|
@ -7,4 +7,12 @@
|
|||
|
||||
using namespace emoji;
|
||||
|
||||
// a null terminated string_view
|
||||
template<size_t N>
|
||||
static consteval std::u16string_view
|
||||
null_literal(const char16_t (&lit)[N])
|
||||
{
|
||||
return std::u16string_view(lit, N);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ class Emoji(object):
|
|||
def generate_qml_list(**kwargs):
|
||||
entrycount = sum([len(c[1]) for c in kwargs.items()])
|
||||
tmpl = Template('''
|
||||
const std::array<Emoji, {{ entrycount }} > emoji::Provider::emoji = {
|
||||
constexpr std::array<Emoji, {{ entrycount }} > emoji::Provider::emoji = {
|
||||
{%- for c in kwargs.items() %}
|
||||
// {{ c[0].capitalize() }}
|
||||
{%- for e in c[1] %}
|
||||
Emoji{QStringLiteral(u"{{ e.code }}"), QStringLiteral(u"{{ e.shortname }}"), QStringLiteral(u"{{ e.unicodename }}"), emoji::Emoji::Category::{{ c[0].capitalize() }}},
|
||||
Emoji{null_literal(u"{{ e.code }}"), null_literal(u"{{ e.shortname }}"), null_literal(u"{{ e.unicodename }}"), emoji::Emoji::Category::{{ c[0].capitalize() }}},
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
};
|
||||
|
|
20
src/Config.h
20
src/Config.h
|
@ -17,15 +17,15 @@
|
|||
namespace conf {
|
||||
|
||||
namespace modals {
|
||||
constexpr int WIDGET_MARGIN = 20;
|
||||
constexpr int WIDGET_SPACING = 15;
|
||||
inline constexpr int WIDGET_MARGIN = 20;
|
||||
inline constexpr int WIDGET_SPACING = 15;
|
||||
|
||||
constexpr auto LABEL_MEDIUM_SIZE_RATIO = 1.3;
|
||||
inline constexpr auto LABEL_MEDIUM_SIZE_RATIO = 1.3;
|
||||
}
|
||||
|
||||
namespace strings {
|
||||
const QString url_html = QStringLiteral("<a href=\"\\1\">\\1</a>");
|
||||
const QRegularExpression url_regex(
|
||||
inline const QString url_html = QStringLiteral("<a href=\"\\1\">\\1</a>");
|
||||
inline const QRegularExpression url_regex(
|
||||
// match an unquoted URL
|
||||
[]() {
|
||||
const auto general_unicode = QStringLiteral(
|
||||
|
@ -78,17 +78,17 @@ const QRegularExpression url_regex(
|
|||
}(),
|
||||
QRegularExpression::UseUnicodePropertiesOption);
|
||||
// A matrix link to be converted back to markdown
|
||||
static const QRegularExpression
|
||||
inline const QRegularExpression
|
||||
matrixToLink(QStringLiteral(R"(<a href=\"(https://matrix.to/#/.*?)\">(.*?)</a>)"));
|
||||
}
|
||||
|
||||
// Window geometry.
|
||||
namespace window {
|
||||
constexpr int height = 600;
|
||||
constexpr int width = 1066;
|
||||
inline constexpr int height = 600;
|
||||
inline constexpr int width = 1066;
|
||||
|
||||
constexpr int minHeight = 340;
|
||||
constexpr int minWidth = 340;
|
||||
inline constexpr int minHeight = 340;
|
||||
inline constexpr int minWidth = 340;
|
||||
} // namespace window
|
||||
|
||||
} // namespace conf
|
||||
|
|
|
@ -57,17 +57,17 @@ EmojiModel::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
case CompletionModel::CompletionRole:
|
||||
case static_cast<int>(EmojiModel::Roles::Unicode):
|
||||
return Provider::emoji[index.row()].unicode;
|
||||
return Provider::emoji[index.row()].unicode();
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
return Provider::emoji[index.row()].shortName + ", " +
|
||||
Provider::emoji[index.row()].unicodeName;
|
||||
return Provider::emoji[index.row()].shortName() + ", " +
|
||||
Provider::emoji[index.row()].unicodeName();
|
||||
case CompletionModel::SearchRole2:
|
||||
case static_cast<int>(EmojiModel::Roles::UnicodeName):
|
||||
return Provider::emoji[index.row()].unicodeName;
|
||||
return Provider::emoji[index.row()].unicodeName();
|
||||
case CompletionModel::SearchRole:
|
||||
case static_cast<int>(EmojiModel::Roles::ShortName):
|
||||
return Provider::emoji[index.row()].shortName;
|
||||
return Provider::emoji[index.row()].shortName();
|
||||
case static_cast<int>(EmojiModel::Roles::Category):
|
||||
return QVariant::fromValue(Provider::emoji[index.row()].category);
|
||||
|
||||
|
|
22128
src/emoji/Provider.cpp
22128
src/emoji/Provider.cpp
File diff suppressed because it is too large
Load diff
|
@ -31,15 +31,59 @@ public:
|
|||
};
|
||||
Q_ENUM(Category)
|
||||
|
||||
Q_PROPERTY(const QString &unicode MEMBER unicode)
|
||||
Q_PROPERTY(const QString &shortName MEMBER shortName)
|
||||
Q_PROPERTY(const QString &unicodeName MEMBER unicodeName)
|
||||
Q_PROPERTY(QString unicode READ unicode CONSTANT)
|
||||
Q_PROPERTY(QString shortName READ shortName CONSTANT)
|
||||
Q_PROPERTY(QString unicodeName READ unicodeName CONSTANT)
|
||||
Q_PROPERTY(emoji::Emoji::Category category MEMBER category)
|
||||
|
||||
public:
|
||||
QString unicode;
|
||||
QString shortName;
|
||||
QString unicodeName;
|
||||
constexpr Emoji(std::u16string_view unicode,
|
||||
std::u16string_view shortName,
|
||||
std::u16string_view unicodeName,
|
||||
Category cat)
|
||||
: unicode_(unicode)
|
||||
, shortName_(shortName)
|
||||
, unicodeName_(unicodeName)
|
||||
, category(cat)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Emoji()
|
||||
: unicode_(u"", 1)
|
||||
, shortName_(u"", 1)
|
||||
, unicodeName_(u"", 1)
|
||||
, category(Category::Search)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Emoji(const Emoji &) = default;
|
||||
constexpr Emoji(Emoji &&) = default;
|
||||
|
||||
constexpr Emoji &operator=(const Emoji &) = default;
|
||||
constexpr Emoji &operator=(Emoji &&) = default;
|
||||
|
||||
QString unicode() const
|
||||
{
|
||||
return QString::fromRawData(reinterpret_cast<const QChar *>(unicode_.data()),
|
||||
unicode_.size());
|
||||
}
|
||||
QString shortName() const
|
||||
{
|
||||
return QString::fromRawData(reinterpret_cast<const QChar *>(shortName_.data()),
|
||||
shortName_.size());
|
||||
}
|
||||
QString unicodeName() const
|
||||
{
|
||||
return QString::fromRawData(reinterpret_cast<const QChar *>(unicodeName_.data()),
|
||||
unicodeName_.size());
|
||||
}
|
||||
|
||||
private:
|
||||
std::u16string_view unicode_;
|
||||
std::u16string_view shortName_;
|
||||
std::u16string_view unicodeName_;
|
||||
|
||||
public:
|
||||
Category category;
|
||||
};
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ auto client_ = std::make_unique<mtx::crypto::OlmClient>();
|
|||
std::map<std::string, std::string> request_id_to_secret_name;
|
||||
|
||||
constexpr auto MEGOLM_ALGO = "m.megolm.v1.aes-sha2";
|
||||
constexpr auto OLM_ALGO = "m.olm.v1.curve25519-aes-sha2";
|
||||
}
|
||||
|
||||
namespace olm {
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
#include <CacheCryptoStructs.h>
|
||||
|
||||
constexpr auto OLM_ALGO = "m.olm.v1.curve25519-aes-sha2";
|
||||
|
||||
namespace olm {
|
||||
Q_NAMESPACE
|
||||
|
||||
|
|
Loading…
Reference in a new issue