From 2f1865855149c150efe60b46cb071de73caca6dc Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 12 Jan 2021 16:31:54 +0200 Subject: [PATCH] de-inline QBuffer::setData() overload for performance reasons Signed-off-by: Ivailo Monev --- src/core/io/qbuffer.cpp | 15 +++++++++++---- src/core/io/qbuffer.h | 3 +-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/io/qbuffer.cpp b/src/core/io/qbuffer.cpp index 4a89e22bd..0b7bc9f2b 100644 --- a/src/core/io/qbuffer.cpp +++ b/src/core/io/qbuffer.cpp @@ -294,7 +294,7 @@ const QByteArray &QBuffer::data() const */ void QBuffer::setData(const QByteArray &data) { - if (isOpen()) { + if (Q_UNLIKELY(isOpen())) { qWarning("QBuffer::setData: Buffer is open"); return; } @@ -303,13 +303,20 @@ void QBuffer::setData(const QByteArray &data) } /*! - \fn void QBuffer::setData(const char *data, int size) - \overload Sets the contents of the internal buffer to be the first \a size - bytes of \a data. + bytes of \a data, does not copy the data. */ +void QBuffer::setData(const char *data, const int len) +{ + if (Q_UNLIKELY(isOpen())) { + qWarning("QBuffer::setData: Buffer is open"); + return; + } + Q_D(QBuffer); + d->buf->setRawData(data, len); +} /*! \reimp diff --git a/src/core/io/qbuffer.h b/src/core/io/qbuffer.h index 8fadc42ed..852d7c73b 100644 --- a/src/core/io/qbuffer.h +++ b/src/core/io/qbuffer.h @@ -63,8 +63,7 @@ public: void setBuffer(QByteArray *a); void setData(const QByteArray &data); - inline void setData(const char *data, const int len) - { setData(QByteArray::fromRawData(data, len)); } + void setData(const char *data, const int len); const QByteArray &data() const; bool open(OpenMode openMode);