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/qjson_p.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/corelib/json/qjson_p.h') diff --git a/src/corelib/json/qjson_p.h b/src/corelib/json/qjson_p.h index 3580e0b61c..5e34845fe3 100644 --- a/src/corelib/json/qjson_p.h +++ b/src/corelib/json/qjson_p.h @@ -573,7 +573,8 @@ public: Entry *entryAt(int i) const { return reinterpret_cast(((char *)this) + table()[i]); } - int indexOf(const QString &key, bool *exists); + int indexOf(const QString &key, bool *exists) const; + int indexOf(QLatin1String key, bool *exists) const; bool isValid() const; }; @@ -675,6 +676,10 @@ public: inline bool operator !=(const QString &key) const { return !operator ==(key); } inline bool operator >=(const QString &key) const; + bool operator==(QLatin1String key) const; + inline bool operator!=(QLatin1String key) const { return !operator ==(key); } + inline bool operator>=(QLatin1String key) const; + bool operator ==(const Entry &other) const; bool operator >=(const Entry &other) const; }; @@ -687,9 +692,20 @@ inline bool Entry::operator >=(const QString &key) const return (shallowKey() >= key); } +inline bool Entry::operator >=(QLatin1String key) const +{ + if (value.latinKey) + return shallowLatin1Key() >= key; + else + return shallowKey() >= key; +} + inline bool operator <(const QString &key, const Entry &e) { return e >= key; } +inline bool operator<(QLatin1String key, const Entry &e) +{ return e >= key; } + class Header { public: -- cgit v1.2.3