Rename QContiguousCache allocate and free functions to say "Data"
The important change is to use functions not called malloc and free. On some old systems or under some weird circumstances, they might be #defined to something different. More importantly, this allows us to quickly verify whether we're using the stdlib.h functions in our public headers. Change-Id: I66b963ac2bc75d64028c04542e62a929e4b36b19 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
649cd98743
commit
9f71ff69f2
@ -56,12 +56,12 @@ void QContiguousCacheData::dump() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QContiguousCacheData *QContiguousCacheData::allocate(int size, int alignment)
|
QContiguousCacheData *QContiguousCacheData::allocateData(int size, int alignment)
|
||||||
{
|
{
|
||||||
return static_cast<QContiguousCacheData *>(qMallocAligned(size, alignment));
|
return static_cast<QContiguousCacheData *>(qMallocAligned(size, alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QContiguousCacheData::free(QContiguousCacheData *data)
|
void QContiguousCacheData::freeData(QContiguousCacheData *data)
|
||||||
{
|
{
|
||||||
qFreeAligned(data);
|
qFreeAligned(data);
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ struct Q_CORE_EXPORT QContiguousCacheData
|
|||||||
// there will be an 8 byte gap here if T requires 16-byte alignment
|
// there will be an 8 byte gap here if T requires 16-byte alignment
|
||||||
// (such as long double on 64-bit platforms, __int128, __float128)
|
// (such as long double on 64-bit platforms, __int128, __float128)
|
||||||
|
|
||||||
static QContiguousCacheData *allocate(int size, int alignment);
|
static QContiguousCacheData *allocateData(int size, int alignment);
|
||||||
static void free(QContiguousCacheData *data);
|
static void freeData(QContiguousCacheData *data);
|
||||||
|
|
||||||
#ifdef QT_QCONTIGUOUSCACHE_DEBUG
|
#ifdef QT_QCONTIGUOUSCACHE_DEBUG
|
||||||
void dump() const;
|
void dump() const;
|
||||||
@ -82,7 +82,7 @@ struct QContiguousCacheTypedData: private QContiguousCacheData
|
|||||||
// private inheritance to avoid aliasing warningss
|
// private inheritance to avoid aliasing warningss
|
||||||
T array[1];
|
T array[1];
|
||||||
|
|
||||||
static inline void free(QContiguousCacheTypedData *data) { QContiguousCacheData::free(data); }
|
static inline void freeData(QContiguousCacheTypedData *data) { QContiguousCacheData::freeData(data); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
explicit QContiguousCache(int capacity = 0);
|
explicit QContiguousCache(int capacity = 0);
|
||||||
QContiguousCache(const QContiguousCache<T> &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); }
|
QContiguousCache(const QContiguousCache<T> &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); }
|
||||||
|
|
||||||
inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) free(p); }
|
inline ~QContiguousCache() { if (!d) return; if (!d->ref.deref()) freeData(p); }
|
||||||
|
|
||||||
inline void detach() { if (d->ref.load() != 1) detach_helper(); }
|
inline void detach() { if (d->ref.load() != 1) detach_helper(); }
|
||||||
inline bool isDetached() const { return d->ref.load() == 1; }
|
inline bool isDetached() const { return d->ref.load() == 1; }
|
||||||
@ -161,8 +161,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
void detach_helper();
|
void detach_helper();
|
||||||
|
|
||||||
QContiguousCacheData *malloc(int aalloc);
|
QContiguousCacheData *allocateData(int aalloc);
|
||||||
void free(Data *x);
|
void freeData(Data *x);
|
||||||
int sizeOfTypedData() {
|
int sizeOfTypedData() {
|
||||||
// this is more or less the same as sizeof(Data), except that it doesn't
|
// this is more or less the same as sizeof(Data), except that it doesn't
|
||||||
// count the padding at the end
|
// count the padding at the end
|
||||||
@ -179,7 +179,7 @@ void QContiguousCache<T>::detach_helper()
|
|||||||
{
|
{
|
||||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
||||||
|
|
||||||
x.d = malloc(d->alloc);
|
x.d = allocateData(d->alloc);
|
||||||
x.d->ref.store(1);
|
x.d->ref.store(1);
|
||||||
x.d->count = d->count;
|
x.d->count = d->count;
|
||||||
x.d->start = d->start;
|
x.d->start = d->start;
|
||||||
@ -206,7 +206,7 @@ void QContiguousCache<T>::detach_helper()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!d->ref.deref())
|
if (!d->ref.deref())
|
||||||
free(p);
|
freeData(p);
|
||||||
d = x.d;
|
d = x.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ void QContiguousCache<T>::setCapacity(int asize)
|
|||||||
return;
|
return;
|
||||||
detach();
|
detach();
|
||||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
||||||
x.d = malloc(asize);
|
x.d = allocateData(asize);
|
||||||
x.d->alloc = asize;
|
x.d->alloc = asize;
|
||||||
x.d->count = qMin(d->count, asize);
|
x.d->count = qMin(d->count, asize);
|
||||||
x.d->offset = d->offset + d->count - x.d->count;
|
x.d->offset = d->offset + d->count - x.d->count;
|
||||||
@ -246,7 +246,7 @@ void QContiguousCache<T>::setCapacity(int asize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* free old */
|
/* free old */
|
||||||
free(p);
|
freeData(p);
|
||||||
d = x.d;
|
d = x.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,26 +268,26 @@ void QContiguousCache<T>::clear()
|
|||||||
d->count = d->start = d->offset = 0;
|
d->count = d->start = d->offset = 0;
|
||||||
} else {
|
} else {
|
||||||
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
|
||||||
x.d = malloc(d->alloc);
|
x.d = allocateData(d->alloc);
|
||||||
x.d->ref.store(1);
|
x.d->ref.store(1);
|
||||||
x.d->alloc = d->alloc;
|
x.d->alloc = d->alloc;
|
||||||
x.d->count = x.d->start = x.d->offset = 0;
|
x.d->count = x.d->start = x.d->offset = 0;
|
||||||
x.d->sharable = true;
|
x.d->sharable = true;
|
||||||
if (!d->ref.deref()) free(p);
|
if (!d->ref.deref()) freeData(p);
|
||||||
d = x.d;
|
d = x.d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline QContiguousCacheData *QContiguousCache<T>::malloc(int aalloc)
|
inline QContiguousCacheData *QContiguousCache<T>::allocateData(int aalloc)
|
||||||
{
|
{
|
||||||
return QContiguousCacheData::allocate(sizeOfTypedData() + (aalloc - 1) * sizeof(T), alignOfTypedData());
|
return QContiguousCacheData::allocateData(sizeOfTypedData() + (aalloc - 1) * sizeof(T), alignOfTypedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QContiguousCache<T>::QContiguousCache(int cap)
|
QContiguousCache<T>::QContiguousCache(int cap)
|
||||||
{
|
{
|
||||||
d = malloc(cap);
|
d = allocateData(cap);
|
||||||
d->ref.store(1);
|
d->ref.store(1);
|
||||||
d->alloc = cap;
|
d->alloc = cap;
|
||||||
d->count = d->start = d->offset = 0;
|
d->count = d->start = d->offset = 0;
|
||||||
@ -299,7 +299,7 @@ QContiguousCache<T> &QContiguousCache<T>::operator=(const QContiguousCache<T> &o
|
|||||||
{
|
{
|
||||||
other.d->ref.ref();
|
other.d->ref.ref();
|
||||||
if (!d->ref.deref())
|
if (!d->ref.deref())
|
||||||
free(d);
|
freeData(d);
|
||||||
d = other.d;
|
d = other.d;
|
||||||
if (!d->sharable)
|
if (!d->sharable)
|
||||||
detach_helper();
|
detach_helper();
|
||||||
@ -323,7 +323,7 @@ bool QContiguousCache<T>::operator==(const QContiguousCache<T> &other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void QContiguousCache<T>::free(Data *x)
|
void QContiguousCache<T>::freeData(Data *x)
|
||||||
{
|
{
|
||||||
if (QTypeInfo<T>::isComplex) {
|
if (QTypeInfo<T>::isComplex) {
|
||||||
int oldcount = d->count;
|
int oldcount = d->count;
|
||||||
@ -336,7 +336,7 @@ void QContiguousCache<T>::free(Data *x)
|
|||||||
i = p->array;
|
i = p->array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x->free(x);
|
x->freeData(x);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void QContiguousCache<T>::append(const T &value)
|
void QContiguousCache<T>::append(const T &value)
|
||||||
|
Loading…
Reference in New Issue
Block a user