From 41a5480cc78f9ba04be50c2481172ef86ca64079 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 10 Jul 2021 08:17:06 +0200 Subject: Hold QRingBuffer and QNonContiguousByteDevice in shared_ptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... instead of QSharedPointer. QSharedPointer performs twice as many atomic operations per pointer copy as std::shared_ptr, and this is private API, we're not bound by BC constraints, so we can port to the more efficient version. Change-Id: I9572a8321aae381e5dbe4a51119f2c9494a8fbc7 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qnoncontiguousbytedevice.cpp | 27 +++++++++++++-------------- src/corelib/io/qnoncontiguousbytedevice_p.h | 17 +++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index cf2da0c896..73075c532f 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -227,10 +227,9 @@ qint64 QNonContiguousByteDeviceByteArrayImpl::pos() const return currentPosition; } -QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QSharedPointer rb) - : QNonContiguousByteDevice(), currentPosition(0) +QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(std::shared_ptr rb) + : QNonContiguousByteDevice(), ringBuffer(std::move(rb)) { - ringBuffer = rb; } QNonContiguousByteDeviceRingBufferImpl::~QNonContiguousByteDeviceRingBufferImpl() @@ -495,44 +494,44 @@ QNonContiguousByteDevice *QNonContiguousByteDeviceFactory::create(QIODevice *dev } /*! - Create a QNonContiguousByteDevice out of a QIODevice, return it in a QSharedPointer. + Create a QNonContiguousByteDevice out of a QIODevice, return it in a std::shared_ptr. For QFile, QBuffer and all other QIODevice, sequential or not. \internal */ -QSharedPointer QNonContiguousByteDeviceFactory::createShared(QIODevice *device) +std::shared_ptr QNonContiguousByteDeviceFactory::createShared(QIODevice *device) { // shortcut if it is a QBuffer if (QBuffer *buffer = qobject_cast(device)) - return QSharedPointer::create(buffer); + return std::make_shared(buffer); // ### FIXME special case if device is a QFile that supports map() // then we can actually deal with the file without using read/peek // generic QIODevice - return QSharedPointer::create(device); // FIXME + return std::make_shared(device); // FIXME } /*! - \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer ringBuffer) + \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr ringBuffer) Create a QNonContiguousByteDevice out of a QRingBuffer. \internal */ -QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer ringBuffer) +QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr ringBuffer) { return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer); } /*! - Create a QNonContiguousByteDevice out of a QRingBuffer, return it in a QSharedPointer. + Create a QNonContiguousByteDevice out of a QRingBuffer, return it in a std::shared_ptr. \internal */ -QSharedPointer QNonContiguousByteDeviceFactory::createShared(QSharedPointer ringBuffer) +std::shared_ptr QNonContiguousByteDeviceFactory::createShared(std::shared_ptr ringBuffer) { - return QSharedPointer::create(std::move(ringBuffer)); + return std::make_shared(std::move(ringBuffer)); } /*! @@ -552,9 +551,9 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by \internal */ -QSharedPointer QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) +std::shared_ptr QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) { - return QSharedPointer::create(byteArray); + return std::make_shared(byteArray); } /*! diff --git a/src/corelib/io/qnoncontiguousbytedevice_p.h b/src/corelib/io/qnoncontiguousbytedevice_p.h index c570480d85..94d8e5ef9c 100644 --- a/src/corelib/io/qnoncontiguousbytedevice_p.h +++ b/src/corelib/io/qnoncontiguousbytedevice_p.h @@ -55,9 +55,10 @@ #include #include #include -#include #include "private/qringbuffer_p.h" +#include + QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QNonContiguousByteDevice : public QObject @@ -85,13 +86,13 @@ class Q_CORE_EXPORT QNonContiguousByteDeviceFactory { public: static QNonContiguousByteDevice *create(QIODevice *device); - static QSharedPointer createShared(QIODevice *device); + static std::shared_ptr createShared(QIODevice *device); static QNonContiguousByteDevice *create(QByteArray *byteArray); - static QSharedPointer createShared(QByteArray *byteArray); + static std::shared_ptr createShared(QByteArray *byteArray); - static QNonContiguousByteDevice *create(QSharedPointer ringBuffer); - static QSharedPointer createShared(QSharedPointer ringBuffer); + static QNonContiguousByteDevice *create(std::shared_ptr ringBuffer); + static std::shared_ptr createShared(std::shared_ptr ringBuffer); static QIODevice *wrap(QNonContiguousByteDevice *byteDevice); }; @@ -119,7 +120,7 @@ protected: class QNonContiguousByteDeviceRingBufferImpl : public QNonContiguousByteDevice { public: - explicit QNonContiguousByteDeviceRingBufferImpl(QSharedPointer rb); + explicit QNonContiguousByteDeviceRingBufferImpl(std::shared_ptr rb); ~QNonContiguousByteDeviceRingBufferImpl(); const char *readPointer(qint64 maximumLength, qint64 &len) override; bool advanceReadPointer(qint64 amount) override; @@ -129,8 +130,8 @@ public: qint64 pos() const override; protected: - QSharedPointer ringBuffer; - qint64 currentPosition; + std::shared_ptr ringBuffer; + qint64 currentPosition = 0; }; class QNonContiguousByteDeviceIoDeviceImpl : public QNonContiguousByteDevice -- cgit v1.2.3