diff options
Diffstat (limited to 'src/corelib/json/qjson.cpp')
-rw-r--r-- | src/corelib/json/qjson.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/corelib/json/qjson.cpp b/src/corelib/json/qjson.cpp index 24fcaf0937..bb98e25fa5 100644 --- a/src/corelib/json/qjson.cpp +++ b/src/corelib/json/qjson.cpp @@ -179,7 +179,29 @@ void Base::removeItems(int pos, int numItems) length -= numItems; } -int Object::indexOf(const QString &key, bool *exists) +int Object::indexOf(const QString &key, bool *exists) const +{ + int min = 0; + int n = length; + while (n > 0) { + int half = n >> 1; + int middle = min + half; + if (*entryAt(middle) >= key) { + n = half; + } else { + min = middle + 1; + n -= half + 1; + } + } + if (min < (int)length && *entryAt(min) == key) { + *exists = true; + return min; + } + *exists = false; + return min; +} + +int Object::indexOf(QLatin1String key, bool *exists) const { int min = 0; int n = length; @@ -248,6 +270,14 @@ bool Entry::operator ==(const QString &key) const return (shallowKey() == key); } +bool Entry::operator==(QLatin1String key) const +{ + if (value.latinKey) + return shallowLatin1Key() == key; + else + return shallowKey() == key; +} + bool Entry::operator ==(const Entry &other) const { if (value.latinKey) { |