summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2019-12-03 12:21:46 +0100
committerLars Knoll <lars.knoll@qt.io>2020-07-06 21:30:33 +0200
commitfbce2e58e6f29dc8dde5618597d53e1b1007b503 (patch)
tree836e966a69b532e140bc3d83ad846999adb75e47 /src/corelib
parentc01804bd1edf00006a76edb1bf33ba9f72a69296 (diff)
Get rid of QArrayData::sharedNull()
Remove the last places where those got used and avoid allocations when we resize to 0. Change-Id: Ib553f4e7ce7cc24c31da15a55a86d18bdf1cc5c3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/text/qbytearray.cpp4
-rw-r--r--src/corelib/tools/qarraydata.cpp25
-rw-r--r--src/corelib/tools/qarraydata.h18
-rw-r--r--src/corelib/tools/qarraydatapointer.h3
4 files changed, 6 insertions, 44 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 350fa3be25..e0f720bc86 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -1732,7 +1732,7 @@ QByteArray QByteArray::nulTerminated() const
QByteArray &QByteArray::prepend(const QByteArray &ba)
{
- if (size() == 0 && d->isStatic() && ba.d.isMutable()) {
+ if (size() == 0 && ba.d.isMutable()) {
*this = ba;
} else if (ba.size() != 0) {
QByteArray tmp = *this;
@@ -1825,7 +1825,7 @@ QByteArray &QByteArray::prepend(char ch)
QByteArray &QByteArray::append(const QByteArray &ba)
{
- if (size() == 0 && d->isStatic() && ba.d.isMutable()) {
+ if (size() == 0 && ba.d.isMutable()) {
*this = ba;
} else if (ba.size() != 0) {
if (d->needsDetach() || size() + ba.size() > capacity())
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index 42599bbf2a..1a369a879a 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -147,25 +147,7 @@ qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t heade
return result;
}
-// End of qtools_p.h implementation
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")
-
-const QArrayData QArrayData::shared_null[2] = {
- { Q_BASIC_ATOMIC_INITIALIZER(-1), 0, 0 }, // shared null
- /* zero initialized terminator */};
-
-static const QArrayData emptyNotNullShared[2] = {
- { Q_BASIC_ATOMIC_INITIALIZER(-1), 0, 0 }, // shared empty
- /* zero initialized terminator */};
-
-QT_WARNING_POP
-
-static const QArrayData &qt_array_empty = emptyNotNullShared[0];
-
-static inline size_t calculateBlockSize(size_t &capacity, size_t objectSize, size_t headerSize,
- uint options)
+static inline size_t calculateBlockSize(size_t &capacity, size_t objectSize, size_t headerSize, uint options)
{
// Calculate the byte size
// allocSize = objectSize * capacity + headerSize, but checked for overflow
@@ -199,9 +181,8 @@ void *QArrayData::allocate(QArrayData **dptr, size_t objectSize, size_t alignmen
&& !(alignment & (alignment - 1)));
if (capacity == 0) {
- // optimization for empty headers
- *dptr = const_cast<QArrayData *>(&qt_array_empty);
- return sharedNullData();
+ *dptr = nullptr;
+ return nullptr;
}
size_t headerSize = sizeof(QArrayData);
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index b3b559e222..fe8827afb8 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -77,24 +77,16 @@ struct Q_CORE_EXPORT QArrayData
/// Returns true if sharing took place
bool ref()
{
- if (!isStatic())
- ref_.ref();
+ ref_.ref();
return true;
}
/// Returns false if deallocation is necessary
bool deref()
{
- if (isStatic())
- return true;
return ref_.deref();
}
- bool isStatic() const
- {
- return ref_.loadRelaxed() == -1;
- }
-
bool isShared() const
{
return ref_.loadRelaxed() != 1;
@@ -133,14 +125,6 @@ struct Q_CORE_EXPORT QArrayData
size_t objectSize, size_t newCapacity, ArrayOptions newOptions = DefaultAllocationFlags) Q_DECL_NOTHROW;
static void deallocate(QArrayData *data, size_t objectSize,
size_t alignment) noexcept;
-
- static const QArrayData shared_null[2];
- static QArrayData *sharedNull() noexcept { return const_cast<QArrayData*>(shared_null); }
- static void *sharedNullData()
- {
- QArrayData *const null = const_cast<QArrayData *>(&shared_null[1]);
- return null;
- }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::ArrayOptions)
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index 8e30373211..1f9a9d840c 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -78,7 +78,6 @@ public:
explicit QArrayDataPointer(QPair<QTypedArrayData<T> *, T *> adata, size_t n = 0)
: d(adata.first), ptr(adata.second), size(int(n))
{
- Q_CHECK_PTR(d);
}
static QArrayDataPointer fromRawData(const T *rawData, size_t length)
@@ -183,7 +182,6 @@ public:
void ref() noexcept { if (d) d->ref(); }
bool deref() noexcept { return !d || d->deref(); }
bool isMutable() const noexcept { return d; }
- bool isStatic() const noexcept { return !d; }
bool isShared() const noexcept { return !d || d->isShared(); }
bool isSharedWith(const QArrayDataPointer &other) const noexcept { return d && d == other.d; }
bool needsDetach() const noexcept { return !d || d->needsDetach(); }
@@ -199,7 +197,6 @@ private:
Q_REQUIRED_RESULT QPair<Data *, T *> clone(QArrayData::ArrayOptions options) const
{
QPair<Data *, T *> pair = Data::allocate(detachCapacity(size), options);
- Q_CHECK_PTR(pair.first);
QArrayDataPointer copy(pair.first, pair.second, 0);
if (size)
copy->copyAppend(begin(), end());