From 5fb843bfaec6907f5ca476423149748d3fc76343 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 8 Jul 2022 09:30:37 +0200 Subject: [PATCH] Port QDataBuffer to qsizetype Reduces the impedance mismatch with "normal" Qt containers. Remove useless inline keywords as a drive-by. Functions defined in the class body are implicitly inline since C++98. C++ declarations are long-winded enough as they are, no need to add more cruft. Also make the ctor explicit, we surely didn't intend to allow implicit conversion from qsizetype to QDataBuffer Task-number: QTBUG-104825 Change-Id: I563dcd825afd63937b87e87fbbd324daaeb49d08 Reviewed-by: Lars Knoll (cherry picked from commit 3f32e4a73a95d287cf427bf0b16a99068a2b4daf) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qdatabuffer_p.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h index b8bb44de6c9..1e62c8d924c 100644 --- a/src/gui/painting/qdatabuffer_p.h +++ b/src/gui/painting/qdatabuffer_p.h @@ -26,7 +26,7 @@ template class QDataBuffer { Q_DISABLE_COPY_MOVE(QDataBuffer) public: - QDataBuffer(int res) + explicit QDataBuffer(qsizetype res) { capacity = res; if (res) { @@ -51,11 +51,11 @@ public: inline bool isEmpty() const { return siz==0; } - inline int size() const { return siz; } + qsizetype size() const { return siz; } inline Type *data() const { return buffer; } - inline Type &at(int i) { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } - inline const Type &at(int i) const { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } + Type &at(qsizetype i) { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } + const Type &at(qsizetype i) const { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } inline Type &last() { Q_ASSERT(!isEmpty()); return buffer[siz-1]; } inline const Type &last() const { Q_ASSERT(!isEmpty()); return buffer[siz-1]; } inline Type &first() { Q_ASSERT(!isEmpty()); return buffer[0]; } @@ -72,12 +72,12 @@ public: --siz; } - inline void resize(int size) { + void resize(qsizetype size) { reserve(size); siz = size; } - inline void reserve(int size) { + void reserve(qsizetype size) { if (size > capacity) { if (capacity == 0) capacity = 1; @@ -88,7 +88,7 @@ public: } } - inline void shrink(int size) { + void shrink(qsizetype size) { capacity = size; if (size) { buffer = (Type*) realloc(static_cast(buffer), capacity * sizeof(Type)); @@ -108,8 +108,8 @@ public: inline QDataBuffer &operator<<(const Type &t) { add(t); return *this; } private: - int capacity; - int siz; + qsizetype capacity; + qsizetype siz; Type *buffer; };