Reduce allocations using QStringLiteral

This commit is contained in:
Nicolas Werner 2021-12-29 04:28:08 +01:00
parent a3c4ebc460
commit d8ead9573b
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
46 changed files with 539 additions and 539 deletions

View file

@ -127,17 +127,17 @@ FlatButton::foregroundColor() const
{
if (!foreground_color_.isValid()) {
if (bg_mode_ == Qt::OpaqueMode) {
return ThemeManager::instance().themeColor("BrightWhite");
return ThemeManager::instance().themeColor(QStringLiteral("BrightWhite"));
}
switch (role_) {
case ui::Role::Primary:
return ThemeManager::instance().themeColor("Blue");
return ThemeManager::instance().themeColor(QStringLiteral("Blue"));
case ui::Role::Secondary:
return ThemeManager::instance().themeColor("Gray");
return ThemeManager::instance().themeColor(QStringLiteral("Gray"));
case ui::Role::Default:
default:
return ThemeManager::instance().themeColor("Black");
return ThemeManager::instance().themeColor(QStringLiteral("Black"));
}
}
@ -157,12 +157,12 @@ FlatButton::backgroundColor() const
if (!background_color_.isValid()) {
switch (role_) {
case ui::Role::Primary:
return ThemeManager::instance().themeColor("Blue");
return ThemeManager::instance().themeColor(QStringLiteral("Blue"));
case ui::Role::Secondary:
return ThemeManager::instance().themeColor("Gray");
return ThemeManager::instance().themeColor(QStringLiteral("Gray"));
case ui::Role::Default:
default:
return ThemeManager::instance().themeColor("Black");
return ThemeManager::instance().themeColor(QStringLiteral("Black"));
}
}
@ -198,7 +198,7 @@ QColor
FlatButton::disabledForegroundColor() const
{
if (!disabled_color_.isValid()) {
return ThemeManager::instance().themeColor("FadedWhite");
return ThemeManager::instance().themeColor(QStringLiteral("FadedWhite"));
}
return disabled_color_;
@ -215,7 +215,7 @@ QColor
FlatButton::disabledBackgroundColor() const
{
if (!disabled_background_color_.isValid()) {
return ThemeManager::instance().themeColor("FadedWhite");
return ThemeManager::instance().themeColor(QStringLiteral("FadedWhite"));
}
return disabled_background_color_;

View file

@ -44,14 +44,14 @@ MxcAnimatedImage::startDownload()
auto encryptionInfo = mtx::accessors::file(*event);
// If the message is a link to a non mxcUrl, don't download it
if (!mxcUrl.startsWith("mxc://")) {
if (!mxcUrl.startsWith(QLatin1String("mxc://"))) {
return;
}
QString suffix = QMimeDatabase().mimeTypeForName(mimeType).preferredSuffix();
const auto url = mxcUrl.toStdString();
const auto name = QString(mxcUrl).remove("mxc://");
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
QFileInfo filename(
QStringLiteral("%1/media_cache/media/%2.%3")
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), name, suffix));

View file

@ -66,7 +66,7 @@ MxcMediaProxy::getVideoSurface()
int
MxcMediaProxy::orientation() const
{
nhlog::ui()->debug("metadata: {}", availableMetaData().join(",").toStdString());
nhlog::ui()->debug("metadata: {}", availableMetaData().join(QStringLiteral(",")).toStdString());
auto orientation = metaData(QMediaMetaData::Orientation).toInt();
nhlog::ui()->debug("Video orientation: {}", orientation);
return orientation;
@ -93,16 +93,16 @@ MxcMediaProxy::startDownload()
auto encryptionInfo = mtx::accessors::file(*event);
// If the message is a link to a non mxcUrl, don't download it
if (!mxcUrl.startsWith("mxc://")) {
if (!mxcUrl.startsWith(QLatin1String("mxc://"))) {
return;
}
QString suffix = QMimeDatabase().mimeTypeForName(mimeType).preferredSuffix();
const auto url = mxcUrl.toStdString();
const auto name = QString(mxcUrl).remove("mxc://");
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
QFileInfo filename(
QString("%1/media_cache/media/%2.%3")
QStringLiteral("%1/media_cache/media/%2.%3")
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), name, suffix));
if (QDir::cleanPath(name) != name) {
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);

View file

@ -29,7 +29,7 @@ Nheko::updateUserProfile()
{
if (cache::client() && cache::client()->isInitialized())
currentUser_.reset(
new UserProfile("", utils::localUser(), ChatPage::instance()->timelineManager()));
new UserProfile(QLatin1String(""), utils::localUser(), ChatPage::instance()->timelineManager()));
else
currentUser_.reset();
emit profileChanged();

View file

@ -235,7 +235,7 @@ QString
RoomSettings::roomTopic() const
{
return utils::replaceEmoji(utils::linkifyMessage(
QString::fromStdString(info_.topic).toHtmlEscaped().replace("\n", "<br>")));
QString::fromStdString(info_.topic).toHtmlEscaped().replace(QLatin1String("\n"), QLatin1String("<br>"))));
}
QString
@ -563,10 +563,10 @@ RoomSettings::updateAvatar()
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(fileName, QMimeDatabase::MatchContent);
const auto format = mime.name().split("/")[0];
const auto format = mime.name().split(QStringLiteral("/"))[0];
QFile file{fileName, this};
if (format != "image") {
if (format != QLatin1String("image")) {
emit displayError(tr("The selected file is not an image"));
return;
}

View file

@ -29,7 +29,7 @@ TextLabel::TextLabel(QWidget *parent)
TextLabel::TextLabel(const QString &text, QWidget *parent)
: QTextBrowser(parent)
{
document()->setDefaultStyleSheet(QString("a {color: %1; }").arg(utils::linkColor()));
document()->setDefaultStyleSheet(QStringLiteral("a {color: %1; }").arg(utils::linkColor()));
setText(text);
setOpenExternalLinks(true);
@ -108,7 +108,7 @@ TextLabel::handleLinkActivation(const QUrl &url)
auto parts = url.toString().split('/');
auto defaultHandler = [](const QUrl &url) { QDesktopServices::openUrl(url); };
if (url.host() != "matrix.to" || parts.isEmpty())
if (url.host() != QLatin1String("matrix.to") || parts.isEmpty())
return defaultHandler(url);
try {

View file

@ -9,31 +9,31 @@
QColor
ThemeManager::themeColor(const QString &key) const
{
if (key == "Black")
if (key == QLatin1String("Black"))
return QColor(0x17, 0x19, 0x19);
else if (key == "BrightWhite")
else if (key == QLatin1String("BrightWhite"))
return QColor(0xEB, 0xEB, 0xEB);
else if (key == "FadedWhite")
else if (key == QLatin1String("FadedWhite"))
return QColor(0xC9, 0xC9, 0xC9);
else if (key == "MediumWhite")
else if (key == QLatin1String("MediumWhite"))
return QColor(0x92, 0x92, 0x92);
else if (key == "BrightGreen")
else if (key == QLatin1String("BrightGreen"))
return QColor(0x1C, 0x31, 0x33);
else if (key == "DarkGreen")
else if (key == QLatin1String("DarkGreen"))
return QColor(0x57, 0x72, 0x75);
else if (key == "LightGreen")
else if (key == QLatin1String("LightGreen"))
return QColor(0x46, 0xA4, 0x51);
else if (key == "Gray")
else if (key == QLatin1String("Gray"))
return QColor(0x5D, 0x65, 0x65);
else if (key == "Red")
else if (key == QLatin1String("Red"))
return QColor(0xE2, 0x28, 0x26);
else if (key == "Blue")
else if (key == QLatin1String("Blue"))
return QColor(0x81, 0xB3, 0xA9);
else if (key == "Transparent")
else if (key == QLatin1String("Transparent"))
return QColor(0, 0, 0, 0);
return (QColor(0, 0, 0, 0));

View file

@ -28,7 +28,7 @@ UserProfile::UserProfile(QString roomid,
, manager(manager_)
, model(parent)
{
globalAvatarUrl = "";
globalAvatarUrl = QLatin1String("");
connect(this,
&UserProfile::globalUsernameRetrieved,
@ -124,7 +124,7 @@ UserProfile::avatarUrl()
bool
UserProfile::isGlobalUserProfile() const
{
return roomid_ == "";
return roomid_ == QLatin1String("");
}
crypto::Trust
@ -297,7 +297,7 @@ UserProfile::updateVerificationStatus()
void
UserProfile::banUser()
{
ChatPage::instance()->banUser(this->userid_, "");
ChatPage::instance()->banUser(this->userid_, QLatin1String(""));
}
// void ignoreUser(){
@ -307,7 +307,7 @@ UserProfile::banUser()
void
UserProfile::kickUser()
{
ChatPage::instance()->kickUser(this->userid_, "");
ChatPage::instance()->kickUser(this->userid_, QLatin1String(""));
}
void
@ -390,10 +390,10 @@ UserProfile::changeAvatar()
QMimeDatabase db;
QMimeType mime = db.mimeTypeForFile(fileName, QMimeDatabase::MatchContent);
const auto format = mime.name().split("/")[0];
const auto format = mime.name().split(QStringLiteral("/"))[0];
QFile file{fileName, this};
if (format != "image") {
if (format != QLatin1String("image")) {
emit displayError(tr("The selected file is not an image"));
return;
}

View file

@ -133,8 +133,8 @@ public:
bool isLoading() const;
TimelineModel *room() const { return model; }
Q_INVOKABLE void verify(QString device = "");
Q_INVOKABLE void unverify(QString device = "");
Q_INVOKABLE void verify(QString device = QLatin1String(""));
Q_INVOKABLE void unverify(QString device = QLatin1String(""));
Q_INVOKABLE void fetchDeviceList(const QString &userID);
Q_INVOKABLE void refreshDevices();
Q_INVOKABLE void banUser();