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 <lars.knoll@gmail.com> (cherry picked from commit 3f32e4a73a95d287cf427bf0b16a99068a2b4daf) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
47c2bec017
commit
5fb843bfae
@ -26,7 +26,7 @@ template <typename Type> class QDataBuffer
|
|||||||
{
|
{
|
||||||
Q_DISABLE_COPY_MOVE(QDataBuffer)
|
Q_DISABLE_COPY_MOVE(QDataBuffer)
|
||||||
public:
|
public:
|
||||||
QDataBuffer(int res)
|
explicit QDataBuffer(qsizetype res)
|
||||||
{
|
{
|
||||||
capacity = res;
|
capacity = res;
|
||||||
if (res) {
|
if (res) {
|
||||||
@ -51,11 +51,11 @@ public:
|
|||||||
|
|
||||||
inline bool isEmpty() const { return siz==0; }
|
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 *data() const { return buffer; }
|
||||||
|
|
||||||
inline Type &at(int i) { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; }
|
Type &at(qsizetype 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]; }
|
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 Type &last() { Q_ASSERT(!isEmpty()); return buffer[siz-1]; }
|
||||||
inline const Type &last() const { 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]; }
|
inline Type &first() { Q_ASSERT(!isEmpty()); return buffer[0]; }
|
||||||
@ -72,12 +72,12 @@ public:
|
|||||||
--siz;
|
--siz;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void resize(int size) {
|
void resize(qsizetype size) {
|
||||||
reserve(size);
|
reserve(size);
|
||||||
siz = size;
|
siz = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void reserve(int size) {
|
void reserve(qsizetype size) {
|
||||||
if (size > capacity) {
|
if (size > capacity) {
|
||||||
if (capacity == 0)
|
if (capacity == 0)
|
||||||
capacity = 1;
|
capacity = 1;
|
||||||
@ -88,7 +88,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void shrink(int size) {
|
void shrink(qsizetype size) {
|
||||||
capacity = size;
|
capacity = size;
|
||||||
if (size) {
|
if (size) {
|
||||||
buffer = (Type*) realloc(static_cast<void*>(buffer), capacity * sizeof(Type));
|
buffer = (Type*) realloc(static_cast<void*>(buffer), capacity * sizeof(Type));
|
||||||
@ -108,8 +108,8 @@ public:
|
|||||||
inline QDataBuffer &operator<<(const Type &t) { add(t); return *this; }
|
inline QDataBuffer &operator<<(const Type &t) { add(t); return *this; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int capacity;
|
qsizetype capacity;
|
||||||
int siz;
|
qsizetype siz;
|
||||||
Type *buffer;
|
Type *buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user