// as this would break strict aliasing rules. (in the case of shared_null)
T array[1];
- static inline void free(QVectorTypedData<T> *x) { QVectorData::freeData(static_cast<QVectorData *>(x)); }
+ static inline void freeTypeData(QVectorTypedData<T> *x) { QVectorData::freeData(static_cast<QVectorData *>(x)); }
};
template <typename T>
explicit QVector(int size);
QVector(int size, const T &t);
inline QVector(const QVector<T> &v) : d(v.d) { d->ref.ref(); }
- inline ~QVector() { if (!d->ref.deref()) free(p); }
+ inline ~QVector() { if (!d->ref.deref()) freeData(p); }
QVector<T> &operator=(const QVector<T> &v);
#ifdef Q_COMPILER_RVALUE_REFS
inline QVector<T> operator=(QVector<T> &&other)
inline int capacity() const { return d->alloc; }
void reserve(int size);
- inline void squeeze() { realloc(d->size, d->size); d->capacity = false; }
+ inline void squeeze() { reallocData(d->size, d->size); d->capacity = false; }
inline void detach() { if (d->ref != 1) detach_helper(); }
inline bool isDetached() const { return d->ref == 1; }
{ std::vector<T> tmp; tmp.reserve(size()); qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
private:
void detach_helper();
- QVectorData *malloc(int alloc);
- void realloc(int size, int alloc);
- void free(Data *d);
+ QVectorData *mallocData(int alloc);
+ void reallocData(int size, int alloc);
+ void freeData(Data *d);
int sizeOfTypedData() {
// this is more or less the same as sizeof(Data), except that it doesn't
// count the padding at the end
template <typename T>
void QVector<T>::detach_helper()
-{ realloc(d->size, d->alloc); }
+{ reallocData(d->size, d->alloc); }
template <typename T>
void QVector<T>::reserve(int asize)
-{ if (asize > d->alloc) realloc(d->size, asize); if (d->ref == 1) d->capacity = true; }
+{ if (asize > d->alloc) reallocData(d->size, asize); if (d->ref == 1) d->capacity = true; }
template <typename T>
void QVector<T>::resize(int asize)
-{ realloc(asize, (asize > d->alloc || (!d->capacity && asize < d->size && asize < (d->alloc >> 1))) ?
+{ reallocData(asize, (asize > d->alloc || (!d->capacity && asize < d->size && asize < (d->alloc >> 1))) ?
QVectorData::grow(sizeOfTypedData(), asize, sizeof(T), QTypeInfo<T>::isStatic)
: d->alloc); }
template <typename T>
QVectorData *o = v.d;
o->ref.ref();
if (!d->ref.deref())
- free(p);
+ freeData(p);
d = o;
return *this;
}
template <typename T>
-inline QVectorData *QVector<T>::malloc(int aalloc)
+inline QVectorData *QVector<T>::mallocData(int aalloc)
{
QVectorData *vectordata = QVectorData::allocate(sizeOfTypedData() + (aalloc - 1) * sizeof(T));
Q_CHECK_PTR(vectordata);
template <typename T>
QVector<T>::QVector(int asize)
{
- d = malloc(asize);
+ d = mallocData(asize);
d->ref = 1;
d->alloc = d->size = asize;
d->capacity = false;
template <typename T>
QVector<T>::QVector(int asize, const T &t)
{
- d = malloc(asize);
+ d = mallocData(asize);
d->ref = 1;
d->alloc = d->size = asize;
d->capacity = false;
template <typename T>
QVector<T>::QVector(std::initializer_list<T> args)
{
- d = malloc(int(args.size()));
+ d = mallocData(int(args.size()));
d->ref = 1;
d->alloc = d->size = int(args.size());
d->capacity = false;
#endif
template <typename T>
-void QVector<T>::free(Data *x)
+void QVector<T>::freeData(Data *x)
{
if (QTypeInfo<T>::isComplex) {
T* b = x->array;
while (i-- != b)
i->~T();
}
- x->free(x);
+ x->freeTypeData(x);
}
template <typename T>
-void QVector<T>::realloc(int asize, int aalloc)
+void QVector<T>::reallocData(int asize, int aalloc)
{
Q_ASSERT(asize <= aalloc);
T *pOld;
if (aalloc != d->alloc || d->ref != 1) {
// (re)allocate memory
if (QTypeInfo<T>::isStatic) {
- x.d = malloc(aalloc);
+ x.d = mallocData(aalloc);
Q_CHECK_PTR(x.p);
x.d->size = 0;
} else if (d->ref != 1) {
- x.d = malloc(aalloc);
+ x.d = mallocData(aalloc);
Q_CHECK_PTR(x.p);
if (QTypeInfo<T>::isComplex) {
x.d->size = 0;
x.d->size++;
}
} QT_CATCH (...) {
- free(x.p);
+ freeData(x.p);
QT_RETHROW;
}
if (d != x.d) {
if (!d->ref.deref())
- free(p);
+ freeData(p);
d = x.d;
}
}
void QVector<T>::append(const T &t)
{
if (d->ref != 1 || d->size + 1 > d->alloc) {
- realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T),
+ reallocData(d->size, QVectorData::grow(sizeOfTypedData(), d->size + 1, sizeof(T),
QTypeInfo<T>::isStatic));
if (QTypeInfo<T>::isComplex)
new (p->array + d->size) T(t);
int offset = int(before - p->array);
if (n != 0) {
if (d->ref != 1 || d->size + n > d->alloc)
- realloc(d->size, QVectorData::grow(sizeOfTypedData(), d->size + n, sizeof(T),
+ reallocData(d->size, QVectorData::grow(sizeOfTypedData(), d->size + n, sizeof(T),
QTypeInfo<T>::isStatic));
if (QTypeInfo<T>::isStatic) {
T *b = p->array + d->size;
QVector<T> &QVector<T>::operator+=(const QVector &l)
{
int newSize = d->size + l.d->size;
- realloc(d->size, newSize);
+ reallocData(d->size, newSize);
T *w = p->array + newSize;
T *i = l.p->array + l.d->size;