Commit 94f69c5d authored by Sergio Martins's avatar Sergio Martins
Browse files

Avoid heap allocations due to fromLatin1()

By replacing it with QStringLiteral, or QLatin1String when passed
to proper overloads.
parent 549f1283
......@@ -260,13 +260,13 @@ static QString join(const QList<qint64> &set)
QString ChangeRecorderPrivate::dumpNotificationListToString() const
{
if (!settings) {
return QString::fromLatin1("No settings set in ChangeRecorder yet.");
return QStringLiteral("No settings set in ChangeRecorder yet.");
}
const QString changesFileName = notificationsFileName();
QFile file(changesFileName);
if (!file.open(QIODevice::ReadOnly)) {
return QString::fromLatin1("Error reading ") + changesFileName;
return QLatin1String("Error reading ") + changesFileName;
}
QString result;
......@@ -330,7 +330,7 @@ QString ChangeRecorderPrivate::dumpNotificationListToString() const
const QString addedTags = join(n.addedTags().toList());
const QString removedTags = join(n.removedTags().toList());
const QString entry = QString::fromLatin1("session=%1 type=%2 operation=%3 items=%4 resource=%5 destResource=%6 parentCollection=%7 parentDestCollection=%8 itemParts=%9 addedFlags=%10 removedFlags=%11 addedTags=%12 removedTags=%13")
const QString entry = QStringLiteral("session=%1 type=%2 operation=%3 items=%4 resource=%5 destResource=%6 parentCollection=%7 parentDestCollection=%8 itemParts=%9 addedFlags=%10 removedFlags=%11 addedTags=%12 removedTags=%13")
.arg(QString::fromLatin1(n.sessionId()))
.arg(typeString)
.arg(operationString)
......
......@@ -47,7 +47,7 @@ ConnectionThread::ConnectionThread(const QByteArray &sessionId, QObject *parent)
const QByteArray sessionLogFile = qgetenv("AKONADI_SESSION_LOGFILE");
if (!sessionLogFile.isEmpty()) {
mLogFile = new QFile(QString::fromLatin1("%1.%2.%3").arg(QString::fromLatin1(sessionLogFile))
mLogFile = new QFile(QStringLiteral("%1.%2.%3").arg(QString::fromLatin1(sessionLogFile))
.arg(QString::number(QApplication::applicationPid()))
.arg(QString::fromLatin1(mSessionId.replace('/', '_'))),
this);
......
......@@ -167,7 +167,7 @@ void Firstrun::instanceCreated(KJob *job)
foreach (const QString &setting, settings.keyList()) {
qDebug() << "Setting up " << setting << " for agent " << instance.identifier();
const QString methodName = QString::fromLatin1("set%1").arg(setting);
const QString methodName = QStringLiteral("set%1").arg(setting);
const QVariant::Type argType = argumentType(iface->metaObject(), methodName);
if (argType == QVariant::Invalid) {
qCritical() << "Setting " << setting << " not found in agent configuration interface of " << instance.identifier();
......
......@@ -105,7 +105,7 @@ void CollectionAttributesSynchronizationJobPrivate::doStart()
connect(interface, SIGNAL(attributesSynchronized(qlonglong)), q, SLOT(slotSynchronized(qlonglong)));
if (interface->isValid()) {
const QDBusMessage reply = interface->call(QString::fromUtf8("synchronizeCollectionAttributes"), collection.id());
const QDBusMessage reply = interface->call(QStringLiteral("synchronizeCollectionAttributes"), collection.id());
if (reply.type() == QDBusMessage::ErrorMessage) {
// This means that the resource doesn't provide a synchronizeCollectionAttributes method, so we just finish the job
q->emitResult();
......@@ -145,7 +145,7 @@ void CollectionAttributesSynchronizationJobPrivate::slotTimeout()
if (instance.status() == AgentInstance::Idle) {
// try again, we might have lost the synchronized() signal
qDebug() << "trying again to sync collection attributes" << collection.id() << instance.identifier();
interface->call(QString::fromUtf8("synchronizeCollectionAttributes"), collection.id());
interface->call(QStringLiteral("synchronizeCollectionAttributes"), collection.id());
}
}
......
......@@ -84,7 +84,7 @@ public:
if (mRequestedItems.isEmpty()) {
QString str = QStringLiteral("All items from collection %1").arg(mCollection.id());
if (mFetchScope.fetchChangedSince().isValid()) {
str += QString::fromLatin1(" changed since %1").arg(mFetchScope.fetchChangedSince().toString());
str += QStringLiteral(" changed since %1").arg(mFetchScope.fetchChangedSince().toString());
}
return str;
......
......@@ -316,7 +316,7 @@ QString Job::errorString() const
break;
}
if (!errorText().isEmpty()) {
str += QString::fromLatin1(" (%1)").arg(errorText());
str += QStringLiteral(" (%1)").arg(errorText());
}
return str;
}
......
......@@ -65,7 +65,7 @@ static QString defaultResourceId(KCoreConfigSkeleton *settings)
static QString dbusServiceName()
{
QString service = QString::fromLatin1("org.kde.pim.SpecialCollections");
QString service = QStringLiteral("org.kde.pim.SpecialCollections");
if (ServerManager::hasInstanceIdentifier()) {
return service + ServerManager::instanceIdentifier();
}
......@@ -329,8 +329,8 @@ void DefaultResourceJobPrivate::resourceCreateResult(KJob *job)
{
agent.setName(mDefaultResourceOptions.value(QStringLiteral("Name")).toString());
QDBusInterface conf(QString::fromLatin1("org.freedesktop.Akonadi.Resource.") + defaultId,
QString::fromLatin1("/Settings"), QString());
QDBusInterface conf(QLatin1String("org.freedesktop.Akonadi.Resource.") + defaultId,
QStringLiteral("/Settings"), QString());
if (!conf.isValid()) {
q->setError(-1);
......@@ -347,7 +347,7 @@ void DefaultResourceJobPrivate::resourceCreateResult(KJob *job)
continue;
}
const QString methodName = QString::fromLatin1("set%1").arg(it.key());
const QString methodName = QStringLiteral("set%1").arg(it.key());
const QVariant::Type argType = argumentType(conf.metaObject(), methodName);
if (argType == QVariant::Invalid) {
q->setError(Job::Unknown);
......
......@@ -272,11 +272,11 @@ QString EntityOrderProxyModel::configString(const QModelIndex &index) const
{
Entity::Id eId = index.data(EntityTreeModel::ItemIdRole).toLongLong();
if (eId != -1) {
return QString::fromLatin1("i") + QString::number(eId);
return QLatin1String("i") + QString::number(eId);
}
eId = index.data(EntityTreeModel::CollectionIdRole).toLongLong();
if (eId != -1) {
return QString::fromLatin1("c") + QString::number(eId);
return QLatin1String("c") + QString::number(eId);
}
Q_ASSERT(!"Invalid entity");
return QString();
......
......@@ -79,11 +79,11 @@ public:
QString bckColor = QApplication::palette().color(QPalette::ToolTipBase).name();
QString txtColor = QApplication::palette().color(QPalette::ToolTipText).name();
QString tip = QString::fromLatin1(
QString tip = QStringLiteral(
"<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n"
);
const QString textDirection = (QApplication::layoutDirection() == Qt::LeftToRight) ? QStringLiteral("left") : QStringLiteral("right");
tip += QString::fromLatin1(
tip += QStringLiteral(
" <tr>\n"
" <td bgcolor=\"%1\" colspan=\"2\" align=\"%4\" valign=\"middle\">\n"
" <div style=\"color: %2; font-weight: bold;\">\n"
......@@ -93,13 +93,13 @@ public:
" </tr>\n"
).arg(txtColor).arg(bckColor).arg(index.data(Qt::DisplayRole).toString()).arg(textDirection);
tip += QString::fromLatin1(
tip += QStringLiteral(
" <tr>\n"
" <td align=\"%1\" valign=\"top\">\n"
).arg(textDirection);
QString tipInfo;
tipInfo += QString::fromLatin1(
tipInfo += QStringLiteral(
" <strong>%1</strong>: %2<br>\n"
" <strong>%3</strong>: %4<br><br>\n"
).arg(i18n("Total Messages")).arg(collection.statistics().count())
......@@ -112,7 +112,7 @@ public:
if (qAbs(percentage) >= 0.01) {
QString percentStr = QString::number(percentage, 'f', 2);
tipInfo += QString::fromLatin1(
tipInfo += QStringLiteral(
" <strong>%1</strong>: %2%<br>\n"
).arg(i18n("Quota")).arg(percentStr);
}
......@@ -121,7 +121,7 @@ public:
KFormat formatter;
qint64 currentFolderSize(collection.statistics().size());
tipInfo += QString::fromLatin1(
tipInfo += QStringLiteral(
" <strong>%1</strong>: %2<br>\n"
).arg(i18n("Storage Size")).arg(formatter.formatByteSize(currentFolderSize));
......@@ -129,7 +129,7 @@ public:
getCountRecursive(index, totalSize);
totalSize -= currentFolderSize;
if (totalSize > 0) {
tipInfo += QString::fromLatin1(
tipInfo += QStringLiteral(
"<strong>%1</strong>: %2<br>"
).arg(i18n("Subfolder Storage Size")).arg(formatter.formatByteSize(totalSize));
}
......@@ -161,7 +161,7 @@ public:
iconPath = KIconLoader::global()->iconPath(QStringLiteral("folder"), -32, false);
}
QString tipIcon = QString::fromLatin1(
QString tipIcon = QStringLiteral(
" <table border=\"0\"><tr><td width=\"32\" height=\"32\" align=\"center\" valign=\"middle\">\n"
" <img src=\"%1\" width=\"%2\" height=\"32\">\n"
" </td></tr></table>\n"
......@@ -169,12 +169,12 @@ public:
).arg(iconPath).arg(icon_size_found) ;
if (QApplication::layoutDirection() == Qt::LeftToRight) {
tip += tipInfo + QString::fromLatin1("</td><td align=\"%3\" valign=\"top\">").arg(textDirection) + tipIcon;
tip += tipInfo + QStringLiteral("</td><td align=\"%3\" valign=\"top\">").arg(textDirection) + tipIcon;
} else {
tip += tipIcon + QString::fromLatin1("</td><td align=\"%3\" valign=\"top\">").arg(textDirection) + tipInfo;
tip += tipIcon + QStringLiteral("</td><td align=\"%3\" valign=\"top\">").arg(textDirection) + tipInfo;
}
tip += QString::fromLatin1(
tip += QLatin1String(
" </tr>" \
"</table>"
);
......
......@@ -200,12 +200,12 @@ bool ServerManager::start()
bool ServerManager::stop()
{
QDBusInterface iface(ServerManager::serviceName(ServerManager::Control),
QString::fromLatin1("/ControlManager"),
QString::fromLatin1("org.freedesktop.Akonadi.ControlManager"));
QStringLiteral("/ControlManager"),
QStringLiteral("org.freedesktop.Akonadi.ControlManager"));
if (!iface.isValid()) {
return false;
}
iface.call(QDBus::NoBlock, QString::fromLatin1("shutdown"));
iface.call(QDBus::NoBlock, QStringLiteral("shutdown"));
sInstance->setState(Stopping);
return true;
}
......@@ -322,11 +322,11 @@ QString ServerManager::agentServiceName(ServiceAgentType agentType, const QStrin
{
switch (agentType) {
case Agent:
return makeServiceName(AKONADI_DBUS_SERVER_SERVICE, QString::fromLatin1(".Agent.%1").arg(identifier));
return makeServiceName(AKONADI_DBUS_SERVER_SERVICE, QStringLiteral(".Agent.%1").arg(identifier));
case Resource:
return makeServiceName(AKONADI_DBUS_SERVER_SERVICE, QString::fromLatin1(".Resource.%1").arg(identifier));
return makeServiceName(AKONADI_DBUS_SERVER_SERVICE, QStringLiteral(".Resource.%1").arg(identifier));
case Preprocessor:
return makeServiceName(AKONADI_DBUS_SERVER_SERVICE, QString::fromLatin1(".Preprocessor.%1").arg(identifier));
return makeServiceName(AKONADI_DBUS_SERVER_SERVICE, QStringLiteral(".Preprocessor.%1").arg(identifier));
}
Q_ASSERT(!"WTF?");
return QString();
......
......@@ -263,12 +263,12 @@ void CollectionStatisticsDelegate::paint(QPainter *painter,
QString unread;
// qCDebug(AKONADIWIDGETS_LOG) << expanded << unreadCount << unreadRecursiveCount;
if (expanded && unreadCount > 0) {
unread = QString::fromLatin1(" (%1)").arg(unreadCount);
unread = QStringLiteral(" (%1)").arg(unreadCount);
} else if (!expanded) {
if (unreadCount != unreadRecursiveCount) {
unread = QString::fromLatin1(" (%1 + %2)").arg(unreadCount).arg(unreadRecursiveCount - unreadCount);
unread = QStringLiteral(" (%1 + %2)").arg(unreadCount).arg(unreadRecursiveCount - unreadCount);
} else if (unreadCount > 0) {
unread = QString::fromLatin1(" (%1)").arg(unreadCount);
unread = QStringLiteral(" (%1)").arg(unreadCount);
}
}
......
......@@ -182,7 +182,7 @@ void CollectionView::dragMoveEvent(QDragMoveEvent *event)
const Collection collection = Collection::fromUrl(url);
if (collection.isValid()) {
if (!supportedContentTypes.contains(QString::fromLatin1("inode/directory"))) {
if (!supportedContentTypes.contains(QStringLiteral("inode/directory"))) {
break;
}
......@@ -193,7 +193,7 @@ void CollectionView::dragMoveEvent(QDragMoveEvent *event)
} else {
QList<QPair<QString, QString> > query = QUrlQuery(url).queryItems();
for (int i = 0; i < query.count(); ++i) {
if (query.at(i).first == QString::fromLatin1("type")) {
if (query.at(i).first == QLatin1String("type")) {
const QString type = query.at(i).second;
if (!supportedContentTypes.contains(type)) {
break;
......
......@@ -97,11 +97,11 @@ private:
QString header() const
{
QString header = QStringLiteral("<html>");
header += QString::fromLatin1("<body text=\"%1\" bgcolor=\"%2\">")
header += QStringLiteral("<body text=\"%1\" bgcolor=\"%2\">")
.arg(KColorScheme(QPalette::Active, KColorScheme::View).foreground().color().name())
.arg(KColorScheme(QPalette::Active, KColorScheme::View).background().color().name());
header += QLatin1String("<center><table>");
header += QString::fromLatin1("<tr><th align=\"center\">%1</th><th align=\"center\">%2</th><td>&nbsp;</td><th align=\"center\">%3</th></tr>")
header += QStringLiteral("<tr><th align=\"center\">%1</th><th align=\"center\">%2</th><td>&nbsp;</td><th align=\"center\">%3</th></tr>")
.arg(mNameTitle)
.arg(mLeftTitle)
.arg(mRightTitle);
......
......@@ -81,7 +81,7 @@ bool DragDropManager::dropAllowed(QDragMoveEvent *event) const
} else { // This is an item.
QList<QPair<QString, QString> > query = QUrlQuery(url).queryItems();
for (int i = 0; i < query.count(); ++i) {
if (query.at(i).first == QString::fromLatin1("type")) {
if (query.at(i).first == QLatin1String("type")) {
const QString type = query.at(i).second;
if (!supportedContentTypes.contains(type)) {
break;
......
......@@ -56,7 +56,7 @@ using namespace Akonadi;
static QString makeLink(const QString &file)
{
return QString::fromLatin1("<a href=\"%1\">%2</a>").arg(file, file);
return QStringLiteral("<a href=\"%1\">%2</a>").arg(file, file);
}
enum SelfTestRole {
......@@ -84,9 +84,9 @@ SelfTestDialog::SelfTestDialog(QWidget *parent)
connect(buttonBox, &QDialogButtonBox::rejected, this, &SelfTestDialog::reject);
mainLayout->addWidget(buttonBox);
user1Button->setText(i18n("Save Report..."));
user1Button->setIcon(QIcon::fromTheme(QString::fromLatin1("document-save")));
user1Button->setIcon(QIcon::fromTheme(QStringLiteral("document-save")));
user2Button->setText(i18n("Copy Report to Clipboard"));
user2Button->setIcon(QIcon::fromTheme(QString::fromLatin1("edit-copy")));
user2Button->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
ui.setupUi(mainWidget);
mTestModel = new QStandardItemModel(this);
......@@ -112,17 +112,17 @@ QStandardItem *SelfTestDialog::report(ResultType type, const KLocalizedString &s
QStandardItem *item = new QStandardItem(summary.toString());
switch (type) {
case Skip:
item->setIcon(QIcon::fromTheme(QString::fromLatin1("dialog-ok")));
item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok")));
break;
case Success:
item->setIcon(QIcon::fromTheme(QString::fromLatin1("dialog-ok-apply")));
item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok-apply")));
break;
case Warning:
item->setIcon(QIcon::fromTheme(QString::fromLatin1("dialog-warning")));
item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning")));
break;
case Error:
default:
item->setIcon(QIcon::fromTheme(QString::fromLatin1("dialog-error")));
item->setIcon(QIcon::fromTheme(QStringLiteral("dialog-error")));
}
item->setEditable(false);
item->setWhatsThis(details.toString());
......@@ -270,7 +270,7 @@ void SelfTestDialog::testMySQLServerLog()
}
const QString logFileName = XdgBaseDirs::saveDir("data", QStringLiteral("akonadi/db_data"))
+ QDir::separator() + QString::fromLatin1("mysql.err");
+ QDir::separator() + QLatin1String("mysql.err");
const QFileInfo logFileInfo(logFileName);
if (!logFileInfo.exists() || logFileInfo.size() == 0) {
report(Success, ki18n("No current MySQL error log found."),
......@@ -493,7 +493,7 @@ void SelfTestDialog::testResources()
void SelfTestDialog::testServerLog()
{
QString serverLog = XdgBaseDirs::saveDir("data", QStringLiteral("akonadi"))
+ QDir::separator() + QString::fromLatin1("akonadiserver.error");
+ QDir::separator() + QLatin1String("akonadiserver.error");
QFileInfo info(serverLog);
if (!info.exists() || info.size() <= 0) {
report(Success, ki18n("No current Akonadi server error log found."),
......@@ -519,7 +519,7 @@ void SelfTestDialog::testServerLog()
void SelfTestDialog::testControlLog()
{
QString controlLog = XdgBaseDirs::saveDir("data", QStringLiteral("akonadi"))
+ QDir::separator() + QString::fromLatin1("akonadi_control.error");
+ QDir::separator() + QLatin1String("akonadi_control.error");
QFileInfo info(controlLog);
if (!info.exists() || info.size() <= 0) {
report(Success, ki18n("No current Akonadi control error log found."),
......
......@@ -1421,7 +1421,7 @@ public:
// new level
QMenu *popup = new QMenu(menu);
const bool moveAction = (type == MoveCollectionToMenu || type == MoveItemToMenu);
popup->setObjectName(QString::fromUtf8("subMenu"));
popup->setObjectName(QStringLiteral("subMenu"));
popup->setTitle(label);
popup->setIcon(icon);
......
......@@ -33,31 +33,31 @@ namespace Tag
inline QString root()
{
return QString::fromLatin1("knut");
return QStringLiteral("knut");
}
inline QString collection()
{
return QString::fromLatin1("collection");
return QStringLiteral("collection");
}
inline QString item()
{
return QString::fromLatin1("item");
return QStringLiteral("item");
}
inline QString attribute()
{
return QString::fromLatin1("attribute");
return QStringLiteral("attribute");
}
inline QString flag()
{
return QString::fromLatin1("flag");
return QStringLiteral("flag");
}
inline QString tag()
{
return QString::fromLatin1("tag");
return QStringLiteral("tag");
}
inline QString payload()
{
return QString::fromLatin1("payload");
return QStringLiteral("payload");
}
}
......@@ -67,35 +67,35 @@ namespace Attr
inline QString remoteId()
{
return QString::fromLatin1("rid");
return QStringLiteral("rid");
}
inline QString attributeType()
{
return QString::fromLatin1("type");
return QStringLiteral("type");
}
inline QString collectionName()
{
return QString::fromLatin1("name");
return QStringLiteral("name");
}
inline QString collectionContentTypes()
{
return QString::fromLatin1("content");
return QStringLiteral("content");
}
inline QString itemMimeType()
{
return QString::fromLatin1("mimetype");
return QStringLiteral("mimetype");
}
inline QString name()
{
return QString::fromLatin1("name");
return QStringLiteral("name");
}
inline QString gid()
{
return QString::fromLatin1("gid");
return QStringLiteral("gid");
}
inline QString type()
{
return QString::fromLatin1("type");
return QStringLiteral("type");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment