QRingBuffer: port internals from int to qsizetype

Since Qt6, QByteArray uses qsizetype as an integral type for offsets
and sizes. In order to support large blocks, we have to migrate to
that as well.

Change-Id: I2c2983129d6a2e0a1e8078cc41d446a26e27288c
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Alex Trotsenko 2021-10-02 20:21:29 +03:00
parent 9a3f4afb70
commit a8823db578
2 changed files with 16 additions and 15 deletions

View File

@ -44,7 +44,7 @@
QT_BEGIN_NAMESPACE
void QRingChunk::allocate(int alloc)
void QRingChunk::allocate(qsizetype alloc)
{
Q_ASSERT(alloc > 0 && size() == 0);
@ -56,7 +56,7 @@ void QRingChunk::detach()
{
Q_ASSERT(isShared());
const int chunkSize = size();
const qsizetype chunkSize = size();
QByteArray x(chunkSize, Qt::Uninitialized);
::memcpy(x.data(), chunk.constData() + headOffset, chunkSize);
chunk = std::move(x);
@ -145,8 +145,8 @@ char *QRingBuffer::reserve(qint64 bytes)
{
Q_ASSERT(bytes > 0 && bytes < MaxByteArraySize);
const int chunkSize = qMax(basicBlockSize, int(bytes));
int tail = 0;
const qsizetype chunkSize = qMax(qint64(basicBlockSize), bytes);
qsizetype tail = 0;
if (bufferSize == 0) {
if (buffers.isEmpty())
buffers.append(QRingChunk(chunkSize));
@ -175,7 +175,7 @@ char *QRingBuffer::reserveFront(qint64 bytes)
{
Q_ASSERT(bytes > 0 && bytes < MaxByteArraySize);
const int chunkSize = qMax(basicBlockSize, int(bytes));
const qsizetype chunkSize = qMax(qint64(basicBlockSize), bytes);
if (bufferSize == 0) {
if (buffers.isEmpty())
buffers.prepend(QRingChunk(chunkSize));
@ -204,7 +204,7 @@ void QRingBuffer::chop(qint64 bytes)
Q_ASSERT(bytes <= bufferSize);
while (bytes > 0) {
const qint64 chunkSize = buffers.constLast().size();
const qsizetype chunkSize = buffers.constLast().size();
if (buffers.size() == 1 || chunkSize > bytes) {
QRingChunk &chunk = buffers.last();

View File

@ -73,7 +73,7 @@ public:
chunk(other.chunk), headOffset(other.headOffset), tailOffset(other.tailOffset)
{
}
explicit inline QRingChunk(int alloc) :
explicit inline QRingChunk(qsizetype alloc) :
chunk(alloc, Qt::Uninitialized), headOffset(0), tailOffset(0)
{
}
@ -104,7 +104,7 @@ public:
}
// allocating and sharing
void allocate(int alloc);
void allocate(qsizetype alloc);
inline bool isShared() const
{
return !chunk.isDetached();
@ -113,19 +113,19 @@ public:
QByteArray toByteArray();
// getters
inline int head() const
inline qsizetype head() const
{
return headOffset;
}
inline int size() const
inline qsizetype size() const
{
return tailOffset - headOffset;
}
inline int capacity() const
inline qsizetype capacity() const
{
return chunk.size();
}
inline int available() const
inline qsizetype available() const
{
return chunk.size() - tailOffset;
}
@ -141,14 +141,14 @@ public:
}
// array management
inline void advance(int offset)
inline void advance(qsizetype offset)
{
Q_ASSERT(headOffset + offset >= 0);
Q_ASSERT(size() - offset > 0);
headOffset += offset;
}
inline void grow(int offset)
inline void grow(qsizetype offset)
{
Q_ASSERT(size() + offset > 0);
Q_ASSERT(head() + size() + offset <= capacity());
@ -172,7 +172,8 @@ public:
private:
QByteArray chunk;
int headOffset, tailOffset;
qsizetype headOffset;
qsizetype tailOffset;
};
Q_DECLARE_SHARED(QRingChunk)