From 8fb45ae5b8b8ad276aeb9bc9e40f351f47523087 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 4 Jun 2012 22:04:13 +0200 Subject: Introduce QArrayData::allocatedCapacity() and use it instead of d->alloc In almost all cases, use d->allocatedCapacity() or d->constAllocatedCapacity() instead of d->alloc, since they do the same thing (right now). In the future, the functions will be changed. There is a separate const version because most const code should not need to know the allocation size -- only mutating code should need to know that There are a few cases where d->alloc was replaced with a better alternative, like d->size. The one case that remains in the code will be replaced by a different test when it's available. Change-Id: I48135469db4caf150f82df93fff42d2309b23719 Reviewed-by: Simon Hausmann --- src/corelib/text/qbytearray.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/text/qbytearray.h') diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index 2808494407..c161e92743 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -502,11 +502,11 @@ inline QByteArray::QByteArray(const QByteArray &a) noexcept : d(a.d) { d->ref.ref(); } inline int QByteArray::capacity() const -{ return d->alloc ? d->alloc - 1 : 0; } +{ int realCapacity = d->constAllocatedCapacity(); return realCapacity ? realCapacity - 1 : 0; } inline void QByteArray::reserve(int asize) { - if (d->ref.isShared() || uint(asize) + 1u > d->alloc) { + if (d->ref.isShared() || asize > capacity()) { reallocData(qMax(uint(size()), uint(asize)) + 1u, d->detachFlags() | Data::CapacityReserved); } else { d->flags |= Data::CapacityReserved; @@ -515,7 +515,7 @@ inline void QByteArray::reserve(int asize) inline void QByteArray::squeeze() { - if (d->ref.isShared() || uint(d->size) + 1u < d->alloc) { + if (d->ref.isShared() || d->size < capacity()) { reallocData(uint(d->size) + 1u, d->detachFlags() & ~Data::CapacityReserved); } else { d->flags &= ~Data::CapacityReserved; -- cgit v1.2.3