summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-01-17 10:22:40 +0100
committerKevin Simons <kevin.simons@nokia.com>2012-01-17 10:33:40 +0100
commitd658c46d96fb540c7814db2084f111c5ea6c1808 (patch)
tree1eaedd2f07441ff1e15db6ebe1663962d8ac5a00
parent4e04496e68880e87990fea47f09e48cfd28af4fe (diff)
Move private methods into the private namespace
There's no reason these methods need to appear in the exported API. Change-Id: I522aaad53c0473a739634e4bb1eabd9bf75d0b80 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Kevin Simons <kevin.simons@nokia.com>
-rw-r--r--src/qjson.cpp87
-rw-r--r--src/qjson_p.h4
-rw-r--r--src/qjsonarray.cpp12
-rw-r--r--src/qjsonobject.cpp6
-rw-r--r--src/qjsonvalue.cpp84
-rw-r--r--src/qjsonvalue.h7
6 files changed, 101 insertions, 99 deletions
diff --git a/src/qjson.cpp b/src/qjson.cpp
index 980b055..db88b03 100644
--- a/src/qjson.cpp
+++ b/src/qjson.cpp
@@ -47,6 +47,10 @@ namespace QtJson
namespace Private
{
+static const Base emptyArray = { { qToLittleEndian(sizeof(Base)) }, { 0 }, { 0 } };
+static const Base emptyObject = { { qToLittleEndian(sizeof(Base)) }, { 0 }, { 0 } };
+
+
void Data::compact()
{
Q_ASSERT(sizeof(Value) == sizeof(offset));
@@ -292,6 +296,89 @@ bool Value::isValid(const Base *b) const
return true;
}
+/*!
+ \internal
+ */
+int Value::requiredStorage(const QJsonValue &v, bool *compressed)
+{
+ *compressed = false;
+ switch (v.t) {
+ case QJsonValue::Double:
+ if (Private::compressedNumber(v.dbl) != INT_MAX) {
+ *compressed = true;
+ return 0;
+ }
+ return sizeof(double);
+ case QJsonValue::String: {
+ QString s = v.toString();
+ *compressed = Private::useCompressed(s);
+ return Private::qStringSize(s, *compressed);
+ }
+ case QJsonValue::Array:
+ case QJsonValue::Object:
+ return v.base ? v.base->size : sizeof(Private::Base);
+ case QJsonValue::Undefined:
+ case QJsonValue::Null:
+ case QJsonValue::Bool:
+ break;
+ }
+ return 0;
+}
+
+/*!
+ \internal
+ */
+uint Value::valueToStore(const QJsonValue &v, uint offset)
+{
+ switch (v.t) {
+ case QJsonValue::Undefined:
+ case QJsonValue::Null:
+ break;
+ case QJsonValue::Bool:
+ return v.b;
+ case QJsonValue::Double: {
+ int c = Private::compressedNumber(v.dbl);
+ if (c != INT_MAX)
+ return c;
+ }
+ case QJsonValue::String:
+ case QJsonValue::Array:
+ case QJsonValue::Object:
+ return offset;
+ }
+ return 0;
+}
+
+/*!
+ \internal
+ */
+void Value::copyData(const QJsonValue &v, char *dest, bool compressed)
+{
+ switch (v.t) {
+ case QJsonValue::Double:
+ if (!compressed) {
+ *((quint64 *)dest) = qToLittleEndian(v.ui);
+ }
+ break;
+ case QJsonValue::String: {
+ QString str = v.toString();
+ Private::copyString(dest, str, compressed);
+ break;
+ }
+ case QJsonValue::Array:
+ case QJsonValue::Object: {
+ const Private::Base *b = v.base;
+ if (!b)
+ b = (v.t == QJsonValue::Array ? &emptyArray : &emptyObject);
+ memcpy(dest, b, b->size);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+
}
}
diff --git a/src/qjson_p.h b/src/qjson_p.h
index 36b0659..f14d5a7 100644
--- a/src/qjson_p.h
+++ b/src/qjson_p.h
@@ -462,6 +462,10 @@ struct Value
Base *objectOrArray(const Base *b) const;
bool isValid(const Base *b) const;
+
+ static int requiredStorage(const QJsonValue &v, bool *compressed);
+ static uint valueToStore(const QJsonValue &v, uint offset);
+ static void copyData(const QJsonValue &v, char *dest, bool compressed);
};
inline Value Array::at(int i) const
diff --git a/src/qjsonarray.cpp b/src/qjsonarray.cpp
index 4b63cc3..cdb5fb2 100644
--- a/src/qjsonarray.cpp
+++ b/src/qjsonarray.cpp
@@ -332,7 +332,7 @@ void QJsonArray::insert(int i, const QJsonValue &value)
Q_ASSERT (i >= 0 && i <= (int)(a ? a->length : 0));
bool compressed;
- int valueSize = value.requiredStorage(&compressed);
+ int valueSize = Private::Value::requiredStorage(value, &compressed);
detach(valueSize + sizeof(Private::Value));
@@ -344,9 +344,9 @@ void QJsonArray::insert(int i, const QJsonValue &value)
v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
v.latinOrIntValue = compressed;
v.latinKey = false;
- v.val = value.valueToStore(valueOffset);
+ v.val = Private::Value::valueToStore(value, valueOffset);
if (valueSize)
- value.copyData((char *)a + valueOffset, compressed);
+ Private::Value::copyData(value, (char *)a + valueOffset, compressed);
}
/*!
@@ -360,7 +360,7 @@ void QJsonArray::replace(int i, const QJsonValue &value)
Q_ASSERT (a && i >= 0 && i < (int)(a->length));
bool compressed;
- int valueSize = value.requiredStorage(&compressed);
+ int valueSize = Private::Value::requiredStorage(value, &compressed);
detach(valueSize);
@@ -372,9 +372,9 @@ void QJsonArray::replace(int i, const QJsonValue &value)
v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
v.latinOrIntValue = compressed;
v.latinKey = false;
- v.val = value.valueToStore(valueOffset);
+ v.val = Private::Value::valueToStore(value, valueOffset);
if (valueSize)
- value.copyData((char *)a + valueOffset, compressed);
+ Private::Value::copyData(value, (char *)a + valueOffset, compressed);
++d->compactionCounter;
if (d->compactionCounter > 32 && d->compactionCounter >= (int)a->length/2)
diff --git a/src/qjsonobject.cpp b/src/qjsonobject.cpp
index b3ddfe4..b93bf8a 100644
--- a/src/qjsonobject.cpp
+++ b/src/qjsonobject.cpp
@@ -282,7 +282,7 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &
}
bool latinOrIntValue;
- int valueSize = value.requiredStorage(&latinOrIntValue);
+ int valueSize = Private::Value::requiredStorage(value, &latinOrIntValue);
bool latinKey = Private::useCompressed(key);
int valueOffset = sizeof(Private::Entry) + Private::qStringSize(key, latinKey);
@@ -308,10 +308,10 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &
e->value.type = value.t;
e->value.latinKey = latinKey;
e->value.latinOrIntValue = latinOrIntValue;
- e->value.val = value.valueToStore((char *)e - (char *)o + valueOffset);
+ e->value.val = Private::Value::valueToStore(value, (char *)e - (char *)o + valueOffset);
Private::copyString((char *)(e + 1), key, latinKey);
if (valueSize)
- value.copyData((char *)e + valueOffset, latinOrIntValue);
+ Private::Value::copyData(value, (char *)e + valueOffset, latinOrIntValue);
return iterator(this, pos);
}
diff --git a/src/qjsonvalue.cpp b/src/qjsonvalue.cpp
index f20221e..9933e77 100644
--- a/src/qjsonvalue.cpp
+++ b/src/qjsonvalue.cpp
@@ -51,9 +51,6 @@
namespace QtJson {
-static const Private::Base emptyArray = { { qToLittleEndian(sizeof(Private::Base)) }, { 0 }, { 0 } };
-static const Private::Base emptyObject = { { qToLittleEndian(sizeof(Private::Base)) }, { 0 }, { 0 } };
-
/*!
\class QJsonValue
\ingroup json
@@ -484,87 +481,6 @@ void QJsonValue::detach()
object = static_cast<Private::Object *>(d->header->root());
}
-/*!
- \internal
- */
-int QJsonValue::requiredStorage(bool *compressed) const
-{
- *compressed = false;
- switch (t) {
- case Double:
- if (Private::compressedNumber(dbl) != INT_MAX) {
- *compressed = true;
- return 0;
- }
- return sizeof(double);
- case String: {
- QString s = toString();
- *compressed = Private::useCompressed(s);
- return Private::qStringSize(s, *compressed);
- }
- case Array:
- case Object:
- return base ? base->size : sizeof(Private::Base);
- case Undefined:
- case Null:
- case Bool:
- break;
- }
- return 0;
-}
-
-/*!
- \internal
- */
-uint QJsonValue::valueToStore(uint offset) const
-{
- switch (t) {
- case Undefined:
- case Null:
- break;
- case Bool:
- return b;
- case Double: {
- int c = Private::compressedNumber(dbl);
- if (c != INT_MAX)
- return c;
- }
- case String:
- case Array:
- case Object:
- return offset;
- }
- return 0;
-}
-
-/*!
- \internal
- */
-void QJsonValue::copyData(char *dest, bool compressed) const
-{
- switch (t) {
- case Double:
- if (!compressed) {
- *((quint64 *)dest) = qToLittleEndian(ui);
- }
- break;
- case String: {
- QString str = toString();
- Private::copyString(dest, str, compressed);
- break;
- }
- case Array:
- case Object: {
- const Private::Base *b = base;
- if (!b)
- b = (t == Array ? &emptyArray : &emptyObject);
- memcpy(dest, b, b->size);
- break;
- }
- default:
- break;
- }
-}
/*!
\class QJsonValueRef
diff --git a/src/qjsonvalue.h b/src/qjsonvalue.h
index eba93f5..7aa1c47 100644
--- a/src/qjsonvalue.h
+++ b/src/qjsonvalue.h
@@ -102,7 +102,7 @@ private:
// avoid implicit conversions from char * to bool
inline QJsonValue(const void *) {}
friend class Data;
- friend class Value;
+ friend class Private::Value;
friend class QJsonArray;
friend class QJsonObject;
friend QT_PREPEND_NAMESPACE(QDebug) (QT_PREPEND_NAMESPACE(operator<<)) (QT_PREPEND_NAMESPACE(QDebug), const QJsonValue &);
@@ -111,11 +111,6 @@ private:
void detach();
- // ### These should move to Private::Value
- int requiredStorage(bool *compressed) const;
- uint valueToStore(uint offset) const;
- void copyData(char *dest, bool compressed) const;
-
Type t;
Private::Data *d; // needed for Objects and Arrays
union {