diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2016-01-29 12:46:13 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2016-02-01 20:45:21 +0000 |
commit | 57ca755d2efbdb7268e8014cb4c50c9ea1c65bfc (patch) | |
tree | ff8459ea7129c501526b7c58cbecde50d6d9f857 /src/corelib/tools | |
parent | 9fb5ff56c35177502791f1e979b2eca1881a70e5 (diff) |
QRingBuffer: add append(const char *, qint64) function
This allows to remove a code duplication in several places.
Change-Id: I49f56e951682dbd2968923654a12cba5199a2502
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qringbuffer.cpp | 14 | ||||
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index c3cb60a6f0..7e2d909dcd 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -317,6 +317,20 @@ qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const /*! \internal + Append bytes from data to the end +*/ +void QRingBuffer::append(const char *data, qint64 size) +{ + char *writePointer = reserve(size); + if (size == 1) + *writePointer = *data; + else if (size) + ::memcpy(writePointer, data, size); +} + +/*! + \internal + Append a new buffer to the end */ void QRingBuffer::append(const QByteArray &qba) diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index b1d4401de3..9ff1ec49cf 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -126,6 +126,7 @@ public: Q_CORE_EXPORT qint64 read(char *data, qint64 maxLength); Q_CORE_EXPORT QByteArray read(); Q_CORE_EXPORT qint64 peek(char *data, qint64 maxLength, qint64 pos = 0) const; + Q_CORE_EXPORT void append(const char *data, qint64 size); Q_CORE_EXPORT void append(const QByteArray &qba); inline qint64 skip(qint64 length) { |