summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-02-16 23:27:07 +0100
committerQt by Nokia <qt-info@nokia.com>2012-04-02 16:34:21 +0200
commit646dc6c5daeefa99c9af070802c39bc66dc4f1f0 (patch)
tree98d32dd8f36d4842736755235d5d3bcb0b9ff92d /src/corelib/tools
parente4682cc88000b52e67380b227cc42726c869afe2 (diff)
Introduce QArrayDataOps::appendInitialize
Adds given number of default-initialized elements at end of array. For POD types, initialization is reduced to a single memset call. Other types get default constructed in place. As part of adding a test for the new functionality the arrayOps test was extended to verify objects are being constructed and assigned as desired. Change-Id: I9fb2afe0d92667e76993313fcd370fe129d72b90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qarraydataops.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index 1b8ed3372d..785a26c3a8 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -57,6 +57,16 @@ template <class T>
struct QPodArrayOps
: QTypedArrayData<T>
{
+ void appendInitialize(size_t newSize)
+ {
+ Q_ASSERT(!this->ref.isShared());
+ Q_ASSERT(newSize > uint(this->size));
+ Q_ASSERT(newSize <= this->alloc);
+
+ ::memset(this->end(), 0, (newSize - this->size) * sizeof(T));
+ this->size = newSize;
+ }
+
void copyAppend(const T *b, const T *e)
{
Q_ASSERT(!this->ref.isShared());
@@ -105,6 +115,18 @@ template <class T>
struct QGenericArrayOps
: QTypedArrayData<T>
{
+ void appendInitialize(size_t newSize)
+ {
+ Q_ASSERT(!this->ref.isShared());
+ Q_ASSERT(newSize > uint(this->size));
+ Q_ASSERT(newSize <= this->alloc);
+
+ T *const begin = this->begin();
+ do {
+ new (begin + this->size) T();
+ } while (uint(++this->size) != newSize);
+ }
+
void copyAppend(const T *b, const T *e)
{
Q_ASSERT(!this->ref.isShared());
@@ -215,6 +237,7 @@ template <class T>
struct QMovableArrayOps
: QGenericArrayOps<T>
{
+ // using QGenericArrayOps<T>::appendInitialize;
// using QGenericArrayOps<T>::copyAppend;
// using QGenericArrayOps<T>::destroyAll;