summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qringbuffer.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Replace qMove with std::moveAllan Sandfeld Jensen2019-04-061-1/+1
| | | | | | Change-Id: I67df3ae6b5db0a158f86e75b99f422bd13853bc9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Simplify QRingBuffer::peek()Alex Trotsenko2018-02-221-3/+5
| | | | | | | | Use a range-based for loop instead of index-based access. Change-Id: Ie43aee540062eec4800f39915ebd42d5a3cae4b3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer: replace some checks with assertsAlex Trotsenko2018-01-101-29/+33
| | | | | | | | To avoid the silent exits and potentially dangerous output values, the caller must supply the correct parameters on input. Change-Id: Ia9c56940adbf4ad34605a002dfc5c86b32c4658c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Micro-optimize QRingBuffer::free()Alex Trotsenko2018-01-091-1/+1
| | | | | | | | | Change the condition to strong equal, as 'bytes' was checked against wrong value on the start of the function. Change-Id: I4ec4768b9fff3292af233417c4a5862d72d4eeac Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* QRingBuffer: avoid reallocations of the dataAlex Trotsenko2017-12-301-93/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since its initial implementation, QRingBuffer had the following fragilities in the architecture: - it does not guarantee validity of the pointers, if new data will be appended. As an example, passing an address of the QRingBuffer chunk as a parameter to the WriteFileEx() function on Windows requires the stability of the pointer. So, we can't add new data to the QRingBuffer until the overlapped operation completed (related issues were fixed for QWindowsPipeWriter and QSerialPort in 5.6 branch by introducing an intermediate byte array); - inefficient reallocations in reserve(), if a shared chunk was inserted in the queue (we can get a reallocation in the place where we don't expect it: char *writePtr = buffers.last().data() + tail; <- line #133 ). Proposed solution is to avoid reallocation by allocating a new block instead. That was accomplished by introducing a QRingChunk class which operates on a fixed byte array and implements head/tail pointers strategy for each individual buffer in the queue. So, QRingBuffer is no longer dependent on QByteArray's internal shrink/growth algorithms. Change-Id: I05abab0ad78e22e4815a196037dfc6eff85325d1 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Micro-optimize QRingBuffer::chop()Alex Trotsenko2017-12-191-1/+1
| | | | | | | | Change the condition to strong equal, as 'bytes' was checked against wrong value on the start of the function. Change-Id: Iebd785665ac7bd0941ba4ffd3f315b12efc6ce0b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer::reserve(): remove superfluous assertAlex Trotsenko2016-10-221-1/+0
| | | | | | | | 'bytes' is checked against MaxByteArraySize in the beginning and remains unchanged in the function. Change-Id: Ibd4091b95837db16cf45f845d485bfb189317125 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer: add packet modeAlex Trotsenko2016-07-231-22/+24
| | | | | | | | | | | As a special case, setting the value of chunk size to zero forces QRingBuffer to produce a separate QByteArray on each call which appends the data. So, this enables a packet mode where portions of data are stored independently from each other. Change-Id: I2d0b331211901a289da7d4533e974f06830b5590 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CoreLib: use const (and const APIs) moreAnton Kudryavtsev2016-04-181-6/+6
| | | | | | | | | | For CoW types const methods will be called. Mark store_persistent_indexes() as const, because this method does not modify the object. Change-Id: Ic867913b4fb5aaebfbaaffe1d3be45cf7b646403 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer::read(): remove unneeded byte array allocationAlex Trotsenko2016-02-241-1/+0
| | | | | | | QRingBuffer already works fine with empty list of arrays. Change-Id: I5cd388709686d2980efa3d5129c726e75c0b5c09 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* QRingBuffer: add append(const char *, qint64) functionAlex Trotsenko2016-02-011-0/+14
| | | | | | | This allows to remove a code duplication in several places. Change-Id: I49f56e951682dbd2968923654a12cba5199a2502 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* QRingBuffer: improve indexOf() performanceAlex Trotsenko2015-09-031-7/+6
| | | | | | | Use memchr() instead of scan cycle. Change-Id: Ic77a3e5ad4c5f6c7d2a1df12d150eac45d620744 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer: avoid allocation in c'torAlex Trotsenko2015-08-271-17/+36
| | | | | | | | | | | | | | | | | | Reduces creation time and memory consumption when the buffer is unused. Robin's benchmark: QBENCHMARK { QFile file(filename); } reports the following results (run with -median 10 -iterations 524288): before: 0.00028 msecs per iteration (total: 149, iterations: 524288) after: 0.00017 msecs per iteration (total: 93, iterations: 524288). Change-Id: Ied4e7caeca794b94260b8fc59b3ba656f4719c30 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* QRingBuffer: allow to search from any positionAlex Trotsenko2015-08-271-12/+25
| | | | | | Change-Id: I348cd9da88fc81c3dd0789ce8cce9d80c4524e24 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer::reserveFront(): do not leave empty array in buffer listAlex Trotsenko2015-07-101-2/+6
| | | | | | | Fix the corner case when called on empty buffer. Change-Id: I1316de7fbe69f3db40a7fdde06336e53d82675c9 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Unify QByteArray::MaxSize and MaxAllocSizeUlf Hermann2015-06-161-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | We have established the maximum size qAllocMore can deal with in commit 880986be2357a1f80827d038d770dc2f80300201 and we should use it. The maximum size for byte arrays is reduced by one byte as with the previous code we could make qAllocMore produce ((1 << 31) - extra) by passing (1 << 30). That is not a problem for qAllocMore itself (as long as extra > 0) but it's hard to verify that no related code casts the total sum back to signed int, which would overflow to -1. To make the compiler inline access to the maximum size, a private enum MaxByteArraySize is provided, which can be used in internal code. This fixes the merge of commits 880986be2357a1f80827d038d770dc2f80300201 and c70658d301e274c3aaa1fb6cebe2a5e56db12779 Change-Id: Idb04856f7c2e53ef383063e7555d3083020ff2b7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRingBuffer: merge indexOf() overloadsAlex Trotsenko2015-05-281-18/+0
| | | | | Change-Id: Icfed4a29bc2ac95b3e0300eb4579751fe7e57e77 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Deinline QRingBuffer classAlex Trotsenko2015-05-201-0/+327
Reduce the size of .text section in QtCore by 4.5KB and in QtNetwork by 26.5KB. Change-Id: If7998776166b9681c1e4b24c51d40444aa996d7a Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>