return (shallowKey() == key);
}
-bool Entry::operator >=(const QString &key) const
-{
- if (value.latinKey)
- return (shallowLatin1Key() >= key);
- else
- return (shallowKey() >= key);
-}
-
bool Entry::operator ==(const Entry &other) const
{
if (value.latinKey) {
bool operator ==(const QString &key) const;
inline bool operator !=(const QString &key) const { return !operator ==(key); }
- bool operator >=(const QString &key) const;
+ inline bool operator >=(const QString &key) const;
bool operator ==(const Entry &other) const;
bool operator >=(const Entry &other) const;
};
+inline bool Entry::operator >=(const QString &key) const
+{
+ if (value.latinKey)
+ return (shallowLatin1Key() >= key);
+ else
+ return (shallowKey() >= key);
+}
+
inline bool operator <(const QString &key, const Entry &e)
{ return e >= key; }
+
class Header {
public:
qle_uint tag; // 'qbjs'
Data *clone(Base *b, int reserve = 0)
{
- int size = sizeof(Header) + b->size + reserve;
+ int size = sizeof(Header) + b->size;
+ if (ref.load() == 1 && alloc >= size + reserve)
+ return this;
+
+ if (reserve) {
+ if (reserve < 128)
+ reserve = 128;
+ size = qMax(size + reserve, size *2);
+ }
char *raw = (char *)malloc(size);
Q_CHECK_PTR(raw);
memcpy(raw + sizeof(Header), b, b->size);
void parseNumbers();
void parseJson();
void parseJsonToVariant();
+
void toByteArray();
void fromByteArray();
+
+ void jsonObjectInsert();
+ void variantMapInsert();
};
BenchmarkQtBinaryJson::BenchmarkQtBinaryJson(QObject *parent) : QObject(parent)
}
}
+void BenchmarkQtBinaryJson::jsonObjectInsert()
+{
+ QJsonObject object;
+ QString test(QStringLiteral("testString"));
+ QJsonValue value(1.5);
+
+ QBENCHMARK {
+ for (int i = 0; i < 1000; i++)
+ object.insert("testkey_" + i, value);
+ }
+}
+
+void BenchmarkQtBinaryJson::variantMapInsert()
+{
+ QVariantMap object;
+ QString test(QStringLiteral("testString"));
+ QVariant variantValue(1.5);
+
+ QBENCHMARK {
+ for (int i = 0; i < 1000; i++)
+ object.insert("testkey_" + i, variantValue);
+ }
+}
+
QTEST_MAIN(BenchmarkQtBinaryJson)
#include "tst_bench_qtbinaryjson.moc"