summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-07-10 08:17:06 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-14 20:05:41 +0200
commit41a5480cc78f9ba04be50c2481172ef86ca64079 (patch)
treedc6f24ebaeb292a6ceb2c9346d9193a5581c1fa5 /src/corelib/io
parent6c1bc7798bec6bc48439b297e55d14a9da0a3673 (diff)
Hold QRingBuffer and QNonContiguousByteDevice in shared_ptr
... 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 <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice.cpp27
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice_p.h17
2 files changed, 22 insertions, 22 deletions
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<QRingBuffer> rb)
- : QNonContiguousByteDevice(), currentPosition(0)
+QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(std::shared_ptr<QRingBuffer> 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<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device)
+std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device)
{
// shortcut if it is a QBuffer
if (QBuffer *buffer = qobject_cast<QBuffer*>(device))
- return QSharedPointer<QNonContiguousByteDeviceBufferImpl>::create(buffer);
+ return std::make_shared<QNonContiguousByteDeviceBufferImpl>(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<QNonContiguousByteDeviceIoDeviceImpl>::create(device); // FIXME
+ return std::make_shared<QNonContiguousByteDeviceIoDeviceImpl>(device); // FIXME
}
/*!
- \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer)
+ \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> ringBuffer)
Create a QNonContiguousByteDevice out of a QRingBuffer.
\internal
*/
-QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer)
+QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> 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<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer)
+std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringBuffer)
{
- return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(std::move(ringBuffer));
+ return std::make_shared<QNonContiguousByteDeviceRingBufferImpl>(std::move(ringBuffer));
}
/*!
@@ -552,9 +551,9 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by
\internal
*/
-QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray)
+std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray)
{
- return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray);
+ return std::make_shared<QNonContiguousByteDeviceByteArrayImpl>(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 <QtCore/qbytearray.h>
#include <QtCore/qbuffer.h>
#include <QtCore/qiodevice.h>
-#include <QtCore/QSharedPointer>
#include "private/qringbuffer_p.h"
+#include <memory>
+
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<QNonContiguousByteDevice> createShared(QIODevice *device);
+ static std::shared_ptr<QNonContiguousByteDevice> createShared(QIODevice *device);
static QNonContiguousByteDevice *create(QByteArray *byteArray);
- static QSharedPointer<QNonContiguousByteDevice> createShared(QByteArray *byteArray);
+ static std::shared_ptr<QNonContiguousByteDevice> createShared(QByteArray *byteArray);
- static QNonContiguousByteDevice *create(QSharedPointer<QRingBuffer> ringBuffer);
- static QSharedPointer<QNonContiguousByteDevice> createShared(QSharedPointer<QRingBuffer> ringBuffer);
+ static QNonContiguousByteDevice *create(std::shared_ptr<QRingBuffer> ringBuffer);
+ static std::shared_ptr<QNonContiguousByteDevice> createShared(std::shared_ptr<QRingBuffer> ringBuffer);
static QIODevice *wrap(QNonContiguousByteDevice *byteDevice);
};
@@ -119,7 +120,7 @@ protected:
class QNonContiguousByteDeviceRingBufferImpl : public QNonContiguousByteDevice
{
public:
- explicit QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb);
+ explicit QNonContiguousByteDeviceRingBufferImpl(std::shared_ptr<QRingBuffer> 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<QRingBuffer> ringBuffer;
- qint64 currentPosition;
+ std::shared_ptr<QRingBuffer> ringBuffer;
+ qint64 currentPosition = 0;
};
class QNonContiguousByteDeviceIoDeviceImpl : public QNonContiguousByteDevice