summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2012-04-26 12:06:17 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-30 17:07:27 +0200
commitd17cf14185eb84863549e0119c8b7bd20db78580 (patch)
tree843efdf2b591293fabf8c5a7cf448d9514f35495 /tests/benchmarks/corelib
parent5131aefc1f0c04936e3ef19c9870d884775471e5 (diff)
Implement QVector with QArrayData interface.
Change-Id: I109f46892aed2f6024459812d24922b12358814d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/benchmarks/corelib')
-rw-r--r--tests/benchmarks/corelib/tools/qvector/outofline.cpp33
-rw-r--r--tests/benchmarks/corelib/tools/qvector/qrawvector.h26
-rw-r--r--tests/benchmarks/corelib/tools/qvector/qvector.pro2
3 files changed, 60 insertions, 1 deletions
diff --git a/tests/benchmarks/corelib/tools/qvector/outofline.cpp b/tests/benchmarks/corelib/tools/qvector/outofline.cpp
index bf929780a5..138812833f 100644
--- a/tests/benchmarks/corelib/tools/qvector/outofline.cpp
+++ b/tests/benchmarks/corelib/tools/qvector/outofline.cpp
@@ -79,3 +79,36 @@ std::vector<double> stdvector_fill_and_return_helper()
return v;
}
+const QVectorData QVectorData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, false, 0 };
+
+static inline int alignmentThreshold()
+{
+ // malloc on 32-bit platforms should return pointers that are 8-byte aligned or more
+ // while on 64-bit platforms they should be 16-byte aligned or more
+ return 2 * sizeof(void*);
+}
+
+QVectorData *QVectorData::allocate(int size, int alignment)
+{
+ return static_cast<QVectorData *>(alignment > alignmentThreshold() ? qMallocAligned(size, alignment) : ::malloc(size));
+}
+
+QVectorData *QVectorData::reallocate(QVectorData *x, int newsize, int oldsize, int alignment)
+{
+ if (alignment > alignmentThreshold())
+ return static_cast<QVectorData *>(qReallocAligned(x, newsize, oldsize, alignment));
+ return static_cast<QVectorData *>(realloc(x, newsize));
+}
+
+void QVectorData::free(QVectorData *x, int alignment)
+{
+ if (alignment > alignmentThreshold())
+ qFreeAligned(x);
+ else
+ ::free(x);
+}
+
+int QVectorData::grow(int sizeOfHeader, int size, int sizeOfT)
+{
+ return qAllocMore(size * sizeOfT, sizeOfHeader) / sizeOfT;
+}
diff --git a/tests/benchmarks/corelib/tools/qvector/qrawvector.h b/tests/benchmarks/corelib/tools/qvector/qrawvector.h
index 18d9847c95..7d80c125ea 100644
--- a/tests/benchmarks/corelib/tools/qvector/qrawvector.h
+++ b/tests/benchmarks/corelib/tools/qvector/qrawvector.h
@@ -47,6 +47,7 @@
#include <QtCore/qatomic.h>
#include <QtCore/qalgorithms.h>
#include <QtCore/qlist.h>
+#include <QtCore/private/qtools_p.h>
#include <iterator>
#include <vector>
@@ -59,7 +60,32 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
+struct QVectorData
+{
+ QtPrivate::RefCount ref;
+ int size;
+ uint alloc : 31;
+ uint capacityReserved : 1;
+
+ qptrdiff offset;
+
+ void* data() { return reinterpret_cast<char *>(this) + this->offset; }
+
+ static const QVectorData shared_null;
+ static QVectorData *allocate(int size, int alignment);
+ static QVectorData *reallocate(QVectorData *old, int newsize, int oldsize, int alignment);
+ static void free(QVectorData *data, int alignment);
+ static int grow(int sizeOfHeader, int size, int sizeOfT);
+};
+template <typename T>
+struct QVectorTypedData : QVectorData
+{
+ T* begin() { return reinterpret_cast<T *>(this->data()); }
+ T* end() { return begin() + this->size; }
+
+ static QVectorTypedData *sharedNull() { return static_cast<QVectorTypedData *>(const_cast<QVectorData *>(&QVectorData::shared_null)); }
+};
template <typename T>
class QRawVector
diff --git a/tests/benchmarks/corelib/tools/qvector/qvector.pro b/tests/benchmarks/corelib/tools/qvector/qvector.pro
index e24b16230a..24a65d8ee8 100644
--- a/tests/benchmarks/corelib/tools/qvector/qvector.pro
+++ b/tests/benchmarks/corelib/tools/qvector/qvector.pro
@@ -1,5 +1,5 @@
TARGET = tst_bench_vector
-QT = core testlib
+QT = core testlib core-private
INCLUDEPATH += .
SOURCES += main.cpp outofline.cpp
CONFIG += release