From a5159cc50aa0f8a57b6f736621b359a3bcecbf7e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 28 Apr 2016 09:40:49 +0200 Subject: QJsonObject: add some overloads taking QLatin1String QXmlStreamReader also has QLatin1String overloads, which greatly benefits parsers, since the vast majority of keys in both JSON and XML are US-ASCII. This patch adds such an overload to the JSON parser. The value() function is all typical parsers need, so even though many more QJsonObject functions taking QString could benefit from the same treatment, value() is the single most important one for read-only JSON access. Add some more overloads, too, for functions that don't need more internal scaffolding than value(). Requires adding a dummy op[](QL1S) (forwarding to the QString overload) so as not to make QJsonObject json; json[QLatin1String("key")]; // mutable ambiguous between const op[](QL1S) and mutable op[](QString). [ChangeLog][QtCore][QJsonObject] Added value(), op[] const, find(), constFind(), contains() overloads taking QLatin1String. Change-Id: I00883028956ad949ba5ba2b18dd8a6a25ad5085b Reviewed-by: Lars Knoll --- src/corelib/json/qjsonobject.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/json/qjsonobject.h') diff --git a/src/corelib/json/qjsonobject.h b/src/corelib/json/qjsonobject.h index 6cffbce83a..e238c84d98 100644 --- a/src/corelib/json/qjsonobject.h +++ b/src/corelib/json/qjsonobject.h @@ -86,12 +86,16 @@ public: bool isEmpty() const; QJsonValue value(const QString &key) const; + QJsonValue value(QLatin1String key) const; QJsonValue operator[] (const QString &key) const; + QJsonValue operator[] (QLatin1String key) const { return value(key); } QJsonValueRef operator[] (const QString &key); + QJsonValueRef operator[] (QLatin1String key); void remove(const QString &key); QJsonValue take(const QString &key); bool contains(const QString &key) const; + bool contains(QLatin1String key) const; bool operator==(const QJsonObject &other) const; bool operator!=(const QJsonObject &other) const; @@ -200,8 +204,11 @@ public: typedef iterator Iterator; typedef const_iterator ConstIterator; iterator find(const QString &key); + iterator find(QLatin1String key); const_iterator find(const QString &key) const { return constFind(key); } + const_iterator find(QLatin1String key) const { return constFind(key); } const_iterator constFind(const QString &key) const; + const_iterator constFind(QLatin1String key) const; iterator insert(const QString &key, const QJsonValue &value); // STL compatibility -- cgit v1.2.3