diff options
author | Jędrzej Nowacki <jedrzej.nowacki@nokia.com> | 2012-03-27 13:17:46 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-16 15:51:06 +0200 |
commit | d1f5a85e661de94d115f11536f0f28f72e99b84d (patch) | |
tree | a8521c3890844a531514e0c10b0f6e8cfa556d1e /src/corelib/tools/qbytearray.h | |
parent | 78b780b9a1ca402ee1f9762f617bb4163684ff34 (diff) |
Migrate QByteArray over QArrayData.
For the time being QByteArrayData keeps its independent existence, for
the sake of other modules. Once they have been ported to use the new
initializer macros it can be changed to:
struct QByteArrayData { QArrayData array; };
Extra braces can then be added to the macros.
With respect to source compatibility, the only concern is with other
modules, as QByteArrayData has already changed in incompatible ways with
Qt 4.x
Done-with: João Abecasis
Change-Id: I044e2a680317431777a098feec8839a90a3d3da3
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index b811a0c3e5..648fe6a162 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -44,6 +44,7 @@ #include <QtCore/qrefcount.h> #include <QtCore/qnamespace.h> +#include <QtCore/qarraydata.h> #include <stdlib.h> #include <string.h> @@ -121,6 +122,8 @@ template <typename T> class QList; struct QByteArrayData { + // Keep in sync with QArrayData + QtPrivate::RefCount ref; int size; uint alloc : 31; @@ -132,6 +135,12 @@ struct QByteArrayData inline const char *data() const { return reinterpret_cast<const char *>(this) + offset; } }; +Q_STATIC_ASSERT(sizeof(QArrayData) == sizeof(QByteArrayData)); +Q_STATIC_ASSERT(offsetof(QArrayData, ref) == offsetof(QByteArrayData, ref)); +Q_STATIC_ASSERT(offsetof(QArrayData, size) == offsetof(QByteArrayData, size)); +// Can't use offsetof on bitfield members alloc, capacityReserved +Q_STATIC_ASSERT(offsetof(QArrayData, offset) == offsetof(QByteArrayData, offset)); + template<int N> struct QStaticByteArrayData { QByteArrayData ba; @@ -194,11 +203,10 @@ struct QByteArrayDataPtr # define QByteArrayLiteral(str) (str) #endif - class Q_CORE_EXPORT QByteArray { private: - typedef QByteArrayData Data; + typedef QTypedArrayData<char> Data; public: inline QByteArray(); @@ -399,12 +407,13 @@ public: int length() const { return d->size; } bool isNull() const; - Q_DECL_CONSTEXPR inline QByteArray(QByteArrayDataPtr dd) : d(dd.ptr) {} + Q_DECL_CONSTEXPR inline QByteArray(QByteArrayDataPtr dd) + : d(reinterpret_cast<Data *>(dd.ptr)) + { + } private: operator QNoImplicitBoolCast() const; - static const QStaticByteArrayData<1> shared_null; - static const QStaticByteArrayData<1> shared_empty; Data *d; void reallocData(uint alloc, bool grow = false); void expand(int i); @@ -418,8 +427,8 @@ public: inline DataPtr &data_ptr() { return d; } }; -inline QByteArray::QByteArray(): d(shared_null.data_ptr()) { } -inline QByteArray::~QByteArray() { if (!d->ref.deref()) free(d); } +inline QByteArray::QByteArray(): d(Data::sharedNull()) { } +inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); } inline int QByteArray::size() const { return d->size; } |