From cce29e63108827f551c74221d0aafbbba891dd51 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 18 Jun 2009 16:36:46 +0200 Subject: New constructor QByteArray::QByteArray(int size, enum Qt::Uninitialized) Contrary to the QByteArray::QByteArray(int size, enum Qt::Uninitialized) constructor this does not initialize its data. Reviewed-by: mariusSO --- src/corelib/tools/qbytearray.cpp | 15 +++++++++++++++ src/corelib/tools/qbytearray.h | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 0c45776..142dfeb 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1304,6 +1304,21 @@ QByteArray::QByteArray(int size, char ch) } /*! + \internal + + Constructs a byte array of size \a size with uninitialized contents. +*/ + +QByteArray::QByteArray(int size, enum Qt::Uninitialized) +{ + d = static_cast(qMalloc(sizeof(Data)+size)); + d->ref = 1; + d->alloc = d->size = size; + d->data = d->array; + d->array[size] = '\0'; +} + +/*! Sets the size of the byte array to \a size bytes. If \a size is greater than the current size, the byte array is diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 5cd4d63..3cb10d7 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -42,8 +42,8 @@ #ifndef QBYTEARRAY_H #define QBYTEARRAY_H -#include #include +#include #include #include @@ -127,6 +127,7 @@ public: QByteArray(const char *); QByteArray(const char *, int size); QByteArray(int size, char c); + QByteArray(int size, enum Qt::Uninitialized); inline QByteArray(const QByteArray &); inline ~QByteArray(); -- cgit v0.12