summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusconnection.cpp11
-rw-r--r--src/dbus/qdbusintegrator.cpp6
-rw-r--r--src/dbus/qdbusmisc.cpp15
-rw-r--r--src/dbus/qdbusutil.cpp58
-rw-r--r--src/dbus/qdbusutil_p.h9
5 files changed, 60 insertions, 39 deletions
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp
index ea8c2b0311..cddb7dfb95 100644
--- a/src/dbus/qdbusconnection.cpp
+++ b/src/dbus/qdbusconnection.cpp
@@ -44,6 +44,7 @@
#include <qdebug.h>
#include <qcoreapplication.h>
#include <qstringlist.h>
+#include <qvector.h>
#include <qtimer.h>
#include <qthread.h>
@@ -909,8 +910,8 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
return false;
- QStringList pathComponents = path.split(QLatin1Char('/'));
- if (pathComponents.last().isEmpty())
+ auto pathComponents = path.splitRef(QLatin1Char('/'));
+ if (pathComponents.constLast().isEmpty())
pathComponents.removeLast();
QDBusWriteLocker locker(RegisterObjectAction, d);
@@ -965,7 +966,7 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
}
} else {
// add entry
- node = node->children.insert(it, pathComponents.at(i));
+ node = node->children.insert(it, pathComponents.at(i).toString());
}
// iterate
@@ -1017,8 +1018,8 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
return 0;
- QStringList pathComponents = path.split(QLatin1Char('/'));
- if (pathComponents.last().isEmpty())
+ auto pathComponents = path.splitRef(QLatin1Char('/'));
+ if (pathComponents.constLast().isEmpty())
pathComponents.removeLast();
// lower-bound search for where this object should enter in the tree
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 6d4a27cdb5..cc3080e6db 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -586,7 +586,7 @@ static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNo
}
}
-static void huntAndUnregister(const QStringList &pathComponents, int i, QDBusConnection::UnregisterMode mode,
+static void huntAndUnregister(const QVector<QStringRef> &pathComponents, int i, QDBusConnection::UnregisterMode mode,
QDBusConnectionPrivate::ObjectTreeNode *node)
{
if (pathComponents.count() == i) {
@@ -2335,12 +2335,12 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode)
{
QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
- QStringList pathComponents;
+ QVector<QStringRef> pathComponents;
int i;
if (path == QLatin1String("/")) {
i = 0;
} else {
- pathComponents = path.split(QLatin1Char('/'));
+ pathComponents = path.splitRef(QLatin1Char('/'));
i = 1;
}
diff --git a/src/dbus/qdbusmisc.cpp b/src/dbus/qdbusmisc.cpp
index 6ecd66f3e7..0502bea0ac 100644
--- a/src/dbus/qdbusmisc.cpp
+++ b/src/dbus/qdbusmisc.cpp
@@ -94,14 +94,15 @@ QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
interface.prepend(QLatin1String("local."));
} else {
interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
- QStringList domainName =
- QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
- QString::SkipEmptyParts);
- if (domainName.isEmpty())
+ const QString organizationDomain = QCoreApplication::instance()->organizationDomain();
+ const auto domainName = organizationDomain.splitRef(QLatin1Char('.'), QString::SkipEmptyParts);
+ if (domainName.isEmpty()) {
interface.prepend(QLatin1String("local."));
- else
- for (int i = 0; i < domainName.count(); ++i)
- interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
+ } else {
+ interface.reserve(interface.size() + organizationDomain.size());
+ for (const QStringRef &x : domainName)
+ interface.prepend(QLatin1Char('.')).prepend(x);
+ }
}
}
diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp
index aababd12e9..28341a71a8 100644
--- a/src/dbus/qdbusutil.cpp
+++ b/src/dbus/qdbusutil.cpp
@@ -42,6 +42,7 @@
#include "qdbus_symbols_p.h"
#include <QtCore/qstringlist.h>
+#include <QtCore/qvector.h>
#include "qdbusargument.h"
#include "qdbusunixfiledescriptor.h"
@@ -330,10 +331,10 @@ namespace QDBusUtil
/*!
\internal
- \fn bool QDBusUtil::isValidPartOfObjectPath(const QString &part)
+ \fn bool QDBusUtil::isValidPartOfObjectPath(const QStringRef &part)
See QDBusUtil::isValidObjectPath
*/
- bool isValidPartOfObjectPath(const QString &part)
+ bool isValidPartOfObjectPath(const QStringRef &part)
{
if (part.isEmpty())
return false; // can't be valid if it's empty
@@ -347,6 +348,13 @@ namespace QDBusUtil
}
/*!
+ \internal
+ \fn bool QDBusUtil::isValidPartOfObjectPath(const QString &part)
+
+ \overload
+ */
+
+ /*!
\fn bool QDBusUtil::isValidInterfaceName(const QString &ifaceName)
Returns \c true if this is \a ifaceName is a valid interface name.
@@ -364,36 +372,35 @@ namespace QDBusUtil
if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
- QStringList parts = ifaceName.split(QLatin1Char('.'));
+ const auto parts = ifaceName.splitRef(QLatin1Char('.'));
if (parts.count() < 2)
return false; // at least two parts
- for (int i = 0; i < parts.count(); ++i)
- if (!isValidMemberName(parts.at(i)))
+ for (const QStringRef &part : parts)
+ if (!isValidMemberName(part))
return false;
return true;
}
/*!
- \fn bool QDBusUtil::isValidUniqueConnectionName(const QString &connName)
+ \fn bool QDBusUtil::isValidUniqueConnectionName(const QStringRef &connName)
Returns \c true if \a connName is a valid unique connection name.
Unique connection names start with a colon (":") and are followed by a list of dot-separated
components composed of ASCII letters, digits, the hyphen or the underscore ("_") character.
*/
- bool isValidUniqueConnectionName(const QString &connName)
+ bool isValidUniqueConnectionName(const QStringRef &connName)
{
if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
!connName.startsWith(QLatin1Char(':')))
return false;
- QStringList parts = connName.mid(1).split(QLatin1Char('.'));
+ const auto parts = connName.mid(1).split(QLatin1Char('.'));
if (parts.count() < 1)
return false;
- for (int i = 0; i < parts.count(); ++i) {
- const QString &part = parts.at(i);
+ for (const QStringRef &part : parts) {
if (part.isEmpty())
return false;
@@ -407,6 +414,12 @@ namespace QDBusUtil
}
/*!
+ \fn bool QDBusUtil::isValidUniqueConnectionName(const QString &connName)
+
+ \overload
+ */
+
+ /*!
\fn bool QDBusUtil::isValidBusName(const QString &busName)
Returns \c true if \a busName is a valid bus name.
@@ -429,12 +442,11 @@ namespace QDBusUtil
if (busName.startsWith(QLatin1Char(':')))
return isValidUniqueConnectionName(busName);
- QStringList parts = busName.split(QLatin1Char('.'));
+ const auto parts = busName.splitRef(QLatin1Char('.'));
if (parts.count() < 1)
return false;
- for (int i = 0; i < parts.count(); ++i) {
- const QString &part = parts.at(i);
+ for (const QStringRef &part : parts) {
if (part.isEmpty())
return false;
@@ -450,12 +462,12 @@ namespace QDBusUtil
}
/*!
- \fn bool QDBusUtil::isValidMemberName(const QString &memberName)
+ \fn bool QDBusUtil::isValidMemberName(const QStringRef &memberName)
Returns \c true if \a memberName is a valid member name. A valid member name does not exceed
255 characters in length, is not empty, is composed only of ASCII letters, digits and
underscores, but does not start with a digit.
*/
- bool isValidMemberName(const QString &memberName)
+ bool isValidMemberName(const QStringRef &memberName)
{
if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
@@ -470,6 +482,12 @@ namespace QDBusUtil
}
/*!
+ \fn bool QDBusUtil::isValidMemberName(const QString &memberName)
+
+ \overload
+ */
+
+ /*!
\fn bool QDBusUtil::isValidErrorName(const QString &errorName)
Returns \c true if \a errorName is a valid error name. Valid error names are valid interface
names and vice-versa, so this function is actually an alias for isValidInterfaceName.
@@ -501,12 +519,10 @@ namespace QDBusUtil
path.endsWith(QLatin1Char('/')))
return false;
- QStringList parts = path.split(QLatin1Char('/'));
- Q_ASSERT(parts.count() >= 1);
- parts.removeFirst(); // it starts with /, so we get an empty first part
-
- for (int i = 0; i < parts.count(); ++i)
- if (!isValidPartOfObjectPath(parts.at(i)))
+ // it starts with /, so we skip the empty first part
+ const auto parts = path.midRef(1).split(QLatin1Char('/'));
+ for (const QStringRef &part : parts)
+ if (!isValidPartOfObjectPath(part))
return false;
return true;
diff --git a/src/dbus/qdbusutil_p.h b/src/dbus/qdbusutil_p.h
index 27b61ad7f2..e0ba92be2e 100644
--- a/src/dbus/qdbusutil_p.h
+++ b/src/dbus/qdbusutil_p.h
@@ -68,15 +68,18 @@ namespace QDBusUtil
{
Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
- Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QString &busName);
+ Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QStringRef &busName);
+ bool inline isValidUniqueConnectionName(const QString &busName) { return isValidUniqueConnectionName(QStringRef(&busName)); }
Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
- Q_DBUS_EXPORT bool isValidMemberName(const QString &memberName);
+ Q_DBUS_EXPORT bool isValidMemberName(const QStringRef &memberName);
+ bool inline isValidMemberName(const QString &memberName) { return isValidMemberName(QStringRef(&memberName)); }
Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
- Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QString &path);
+ Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QStringRef &path);
+ bool inline isValidPartOfObjectPath(const QString &path) { return isValidPartOfObjectPath(QStringRef(&path)); }
Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);