qringbuffer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qringbuffer.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Copyright (C) 2015 Alex Trotsenko <alex1973tr@gmail.com>-
5** Contact: http://www.qt.io/licensing/-
6**-
7** This file is part of the QtCore module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL21$-
10** Commercial License Usage-
11** Licensees holding valid commercial Qt licenses may use this file in-
12** accordance with the commercial license agreement provided with the-
13** Software or, alternatively, in accordance with the terms contained in-
14** a written agreement between you and The Qt Company. For licensing terms-
15** and conditions see http://www.qt.io/terms-conditions. For further-
16** information use the contact form at http://www.qt.io/contact-us.-
17**-
18** GNU Lesser General Public License Usage-
19** Alternatively, this file may be used under the terms of the GNU Lesser-
20** General Public License version 2.1 or version 3 as published by the Free-
21** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
22** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
23** following information to ensure the GNU Lesser General Public License-
24** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
25** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
26**-
27** As a special exception, The Qt Company gives you certain additional-
28** rights. These rights are described in The Qt Company LGPL Exception-
29** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
30**-
31** $QT_END_LICENSE$-
32**-
33****************************************************************************/-
34-
35#include "private/qringbuffer_p.h"-
36#include "private/qbytearray_p.h"-
37#include <string.h>-
38-
39QT_BEGIN_NAMESPACE-
40-
41/*!-
42 \internal-
43-
44 Access the bytes at a specified position the out-variable length will-
45 contain the amount of bytes readable from there, e.g. the amount still-
46 the same QByteArray-
47*/-
48const char *QRingBuffer::readPointerAtPosition(qint64 pos, qint64 &length) const-
49{-
50 if (pos >= 0) {
pos >= 0Description
TRUEevaluated 904 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
FALSEnever evaluated
0-904
51 pos += head;-
52 for (int i = 0; i < buffers.size(); ++i) {
i < buffers.size()Description
TRUEevaluated 926 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QRingBuffer
3-926
53 length = (i == tailBuffer ? tail : buffers[i].size());
i == tailBufferDescription
TRUEevaluated 182 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
FALSEevaluated 744 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
182-744
54 if (length > pos) {
length > posDescription
TRUEevaluated 901 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QRingBuffer
25-901
55 length -= pos;-
56 return buffers[i].constData() + pos;
executed 901 times by 2 tests: return buffers[i].constData() + pos;
Executed by:
  • tst_QNetworkReply
  • tst_QRingBuffer
901
57 }-
58 pos -= length;-
59 }
executed 25 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
25
60 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
3
61-
62 length = 0;-
63 return 0;
executed 3 times by 1 test: return 0;
Executed by:
  • tst_QRingBuffer
3
64}-
65-
66void QRingBuffer::free(qint64 bytes)-
67{-
68 while (bytes > 0) {
bytes > 0Description
TRUEevaluated 49496 times by 73 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
FALSEevaluated 1283 times by 12 tests
Evaluated by:
  • tst_QHttpSocketEngine
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_Selftests
  • tst_Spdy
  • tst_qdbuscpp2xml
  • tst_rcc
1283-49496
69 const qint64 blockSize = buffers.first().size() - head;-
70-
71 if (tailBuffer == 0 || blockSize > bytes) {
tailBuffer == 0Description
TRUEevaluated 48497 times by 73 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
FALSEevaluated 999 times by 8 tests
Evaluated by:
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_rcc
blockSize > bytesDescription
TRUEevaluated 527 times by 4 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_Selftests
FALSEevaluated 472 times by 8 tests
Evaluated by:
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_rcc
472-48497
72 // keep a single block around if it does not exceed-
73 // the basic block size, to avoid repeated allocations-
74 // between uses of the buffer-
75 if (bufferSize <= bytes) {
bufferSize <= bytesDescription
TRUEevaluated 47992 times by 73 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
FALSEevaluated 1032 times by 7 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_Selftests
1032-47992
76 if (buffers.first().size() <= basicBlockSize) {
buffers.first(...basicBlockSizeDescription
TRUEevaluated 47590 times by 73 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
FALSEevaluated 402 times by 8 tests
Evaluated by:
  • tst_QImageReader
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_Selftests
  • tst_Spdy
402-47590
77 bufferSize = 0;-
78 head = tail = 0;-
79 } else {
executed 47590 times by 73 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
47590
80 clear(); // try to minify/squeeze us-
81 }
executed 402 times by 8 tests: end of block
Executed by:
  • tst_QImageReader
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_Selftests
  • tst_Spdy
402
82 } else {-
83 Q_ASSERT(bytes < MaxByteArraySize);-
84 head += int(bytes);-
85 bufferSize -= bytes;-
86 }
executed 1032 times by 7 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_Selftests
1032
87 return;
executed 49024 times by 73 tests: return;
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
49024
88 }-
89-
90 bufferSize -= blockSize;-
91 bytes -= blockSize;-
92 buffers.removeFirst();-
93 --tailBuffer;-
94 head = 0;-
95 }
executed 472 times by 8 tests: end of block
Executed by:
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_rcc
472
96}
executed 1283 times by 12 tests: end of block
Executed by:
  • tst_QHttpSocketEngine
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_QTcpSocket
  • tst_Selftests
  • tst_Spdy
  • tst_qdbuscpp2xml
  • tst_rcc
1283
97-
98char *QRingBuffer::reserve(qint64 bytes)-
99{-
100 if (bytes <= 0 || bytes >= MaxByteArraySize)
bytes <= 0Description
TRUEevaluated 27 times by 8 tests
Evaluated by:
  • tst_QFile
  • tst_QHttpSocketEngine
  • tst_QNetworkReply
  • tst_QSharedPointer
  • tst_QTextStream
  • tst_qdbusxml2cpp
  • tst_qmakelib
  • tst_qnetworkreply - unknown status
FALSEevaluated 202012 times by 83 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
bytes >= MaxByteArraySizeDescription
TRUEnever evaluated
FALSEevaluated 202012 times by 83 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
0-202012
101 return 0;
executed 27 times by 8 tests: return 0;
Executed by:
  • tst_QFile
  • tst_QHttpSocketEngine
  • tst_QNetworkReply
  • tst_QSharedPointer
  • tst_QTextStream
  • tst_qdbusxml2cpp
  • tst_qmakelib
  • tst_qnetworkreply - unknown status
27
102-
103 const qint64 newSize = bytes + tail;-
104 // if need buffer reallocation-
105 if (newSize > buffers.last().size()) {
newSize > buff....last().size()Description
TRUEevaluated 23888 times by 83 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
FALSEevaluated 178124 times by 65 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QIODevice
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • ...
23888-178124
106 if (newSize > buffers.last().capacity() && (tail >= basicBlockSize
newSize > buff...t().capacity()Description
TRUEevaluated 11033 times by 83 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
FALSEevaluated 12855 times by 7 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QSslSocket
  • tst_Selftests
  • tst_qmake
tail >= basicBlockSizeDescription
TRUEevaluated 661 times by 9 tests
Evaluated by:
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qmake
  • tst_rcc
FALSEevaluated 10372 times by 83 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
661-12855
107 || newSize >= MaxByteArraySize)) {
newSize >= MaxByteArraySizeDescription
TRUEnever evaluated
FALSEevaluated 10372 times by 83 tests
Evaluated by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
0-10372
108 // shrink this buffer to its current size-
109 buffers.last().resize(tail);-
110-
111 // create a new QByteArray-
112 buffers.append(QByteArray());-
113 ++tailBuffer;-
114 tail = 0;-
115 }
executed 661 times by 9 tests: end of block
Executed by:
  • tst_QLocalSocket
  • tst_QNetworkReply
  • tst_QProcess
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qmake
  • tst_rcc
661
116 buffers.last().resize(qMax(basicBlockSize, tail + int(bytes)));-
117 }
executed 23888 times by 83 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
23888
118-
119 char *writePtr = buffers.last().data() + tail;-
120 bufferSize += bytes;-
121 Q_ASSERT(bytes < MaxByteArraySize);-
122 tail += int(bytes);-
123 return writePtr;
executed 202012 times by 83 tests: return writePtr;
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QColorDialog
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDir
  • tst_QEventLoop
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFont
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QGuiEventLoop
  • tst_QHttpNetworkConnection
  • ...
202012
124}-
125-
126/*!-
127 \internal-
128-
129 Allocate data at buffer head-
130*/-
131char *QRingBuffer::reserveFront(qint64 bytes)-
132{-
133 if (bytes <= 0 || bytes >= MaxByteArraySize)
bytes <= 0Description
TRUEnever evaluated
FALSEevaluated 265 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
bytes >= MaxByteArraySizeDescription
TRUEnever evaluated
FALSEevaluated 265 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
0-265
134 return 0;
never executed: return 0;
0
135-
136 if (head < bytes) {
head < bytesDescription
TRUEevaluated 19 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
FALSEevaluated 246 times by 1 test
Evaluated by:
  • tst_QRingBuffer
19-246
137 buffers.first().remove(0, head);-
138 if (tailBuffer == 0)
tailBuffer == 0Description
TRUEevaluated 12 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QRingBuffer
7-12
139 tail -= head;
executed 12 times by 2 tests: tail -= head;
Executed by:
  • tst_QProcess
  • tst_QRingBuffer
12
140-
141 head = qMax(basicBlockSize, int(bytes));-
142 if (bufferSize == 0) {
bufferSize == 0Description
TRUEevaluated 10 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QRingBuffer
9-10
143 tail = head;-
144 } else {
executed 10 times by 2 tests: end of block
Executed by:
  • tst_QProcess
  • tst_QRingBuffer
10
145 buffers.prepend(QByteArray());-
146 ++tailBuffer;-
147 }
executed 9 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
9
148 buffers.first().resize(head);-
149 }
executed 19 times by 2 tests: end of block
Executed by:
  • tst_QProcess
  • tst_QRingBuffer
19
150-
151 head -= int(bytes);-
152 bufferSize += bytes;-
153 return buffers.first().data() + head;
executed 265 times by 2 tests: return buffers.first().data() + head;
Executed by:
  • tst_QProcess
  • tst_QRingBuffer
265
154}-
155-
156void QRingBuffer::chop(qint64 bytes)-
157{-
158 while (bytes > 0) {
bytes > 0Description
TRUEevaluated 3660 times by 30 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QRingBuffer
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • ...
FALSEevaluated 34687 times by 25 tests
Evaluated by:
  • tst_Lancelot
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedPointer
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • tst_qmakelib
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
3660-34687
159 if (tailBuffer == 0 || tail > bytes) {
tailBuffer == 0Description
TRUEevaluated 3574 times by 30 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QRingBuffer
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • ...
FALSEevaluated 86 times by 6 tests
Evaluated by:
  • tst_QProcess
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qmake
  • tst_rcc
tail > bytesDescription
TRUEevaluated 79 times by 6 tests
Evaluated by:
  • tst_QProcess
  • tst_QSharedPointer
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qmake
  • tst_rcc
FALSEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_Selftests
7-3574
160 // keep a single block around if it does not exceed-
161 // the basic block size, to avoid repeated allocations-
162 // between uses of the buffer-
163 if (bufferSize <= bytes) {
bufferSize <= bytesDescription
TRUEevaluated 2635 times by 30 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QRingBuffer
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • ...
FALSEevaluated 1018 times by 24 tests
Evaluated by:
  • tst_Lancelot
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • tst_qmakelib
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
1018-2635
164 if (buffers.first().size() <= basicBlockSize) {
buffers.first(...basicBlockSizeDescription
TRUEevaluated 2634 times by 29 tests
Evaluated by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • tst_qmakelib
  • ...
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QRingBuffer
1-2634
165 bufferSize = 0;-
166 head = tail = 0;-
167 } else {
executed 2634 times by 29 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • tst_qmakelib
  • ...
2634
168 clear(); // try to minify/squeeze us-
169 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QRingBuffer
1
170 } else {-
171 Q_ASSERT(bytes < MaxByteArraySize);-
172 tail -= int(bytes);-
173 bufferSize -= bytes;-
174 }
executed 1018 times by 24 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QRingBuffer
  • tst_QSharedPointer
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • tst_qmakelib
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
1018
175 return;
executed 3653 times by 30 tests: return;
Executed by:
  • tst_Lancelot
  • tst_QApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QDir
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QRingBuffer
  • tst_QSharedMemory
  • tst_QSharedPointer
  • tst_QSystemSemaphore
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • ...
3653
176 }-
177-
178 bufferSize -= tail;-
179 bytes -= tail;-
180 buffers.removeLast();-
181 --tailBuffer;-
182 tail = buffers.last().size();-
183 }
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QProcess
  • tst_Selftests
7
184}
executed 34687 times by 25 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • tst_QDBusConnection
  • tst_QDBusConnection_SpyHook
  • tst_QDBusInterface
  • tst_QDBusMarshall
  • tst_QFont
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QObject
  • tst_QProcess
  • tst_QProcess_and_GuiEventLoop
  • tst_QSharedPointer
  • tst_QUuid
  • tst_Selftests
  • tst_qdbuscpp2xml
  • tst_qdbusxml2cpp
  • tst_qmake
  • tst_qmakelib
  • tst_qmessagehandler
  • tst_qprocess - unknown status
  • tst_rcc
  • tst_uic
34687
185-
186void QRingBuffer::clear()-
187{-
188 buffers.erase(buffers.begin() + 1, buffers.end());-
189 buffers.first().clear();-
190-
191 head = tail = 0;-
192 tailBuffer = 0;-
193 bufferSize = 0;-
194}
executed 72606 times by 210 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusAbstractAdaptor
  • tst_QDBusAbstractInterface
  • ...
72606
195-
196qint64 QRingBuffer::indexOf(char c, qint64 maxLength) const-
197{-
198 qint64 index = 0;-
199 qint64 j = head;-
200 for (int i = 0; index < maxLength && i < buffers.size(); ++i) {
index < maxLengthDescription
TRUEevaluated 6467 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 256 times by 2 tests
Evaluated by:
  • tst_QProcess
  • tst_QRingBuffer
i < buffers.size()Description
TRUEevaluated 6467 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEnever evaluated
0-6467
201 const char *ptr = buffers[i].constData() + j;-
202 j = qMin(index + (i == tailBuffer ? tail : buffers[i].size()) - j, maxLength);-
203-
204 while (index < j) {
index < jDescription
TRUEevaluated 97702 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 5954 times by 1 test
Evaluated by:
  • tst_QRingBuffer
5954-97702
205 if (*ptr++ == c)
*ptr++ == cDescription
TRUEevaluated 513 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 97189 times by 1 test
Evaluated by:
  • tst_QRingBuffer
513-97189
206 return index;
executed 513 times by 1 test: return index;
Executed by:
  • tst_QRingBuffer
513
207 ++index;-
208 }
executed 97189 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
97189
209 j = 0;-
210 }
executed 5954 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
5954
211 return -1;
executed 256 times by 2 tests: return -1;
Executed by:
  • tst_QProcess
  • tst_QRingBuffer
256
212}-
213-
214qint64 QRingBuffer::read(char *data, qint64 maxLength)-
215{-
216 const qint64 bytesToRead = qMin(size(), maxLength);-
217 qint64 readSoFar = 0;-
218 while (readSoFar < bytesToRead) {
readSoFar < bytesToReadDescription
TRUEevaluated 513 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 513 times by 1 test
Evaluated by:
  • tst_QRingBuffer
513
219 const qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,-
220 nextDataBlockSize());-
221 if (data)
dataDescription
TRUEevaluated 513 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEnever evaluated
0-513
222 memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock);
executed 513 times by 1 test: memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock);
Executed by:
  • tst_QRingBuffer
513
223 readSoFar += bytesToReadFromThisBlock;-
224 free(bytesToReadFromThisBlock);-
225 }
executed 513 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
513
226 return readSoFar;
executed 513 times by 1 test: return readSoFar;
Executed by:
  • tst_QRingBuffer
513
227}-
228-
229/*!-
230 \internal-
231-
232 Read an unspecified amount (will read the first buffer)-
233*/-
234QByteArray QRingBuffer::read()-
235{-
236 if (bufferSize == 0)
bufferSize == 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QRingBuffer
0-3
237 return QByteArray();
never executed: return QByteArray();
0
238-
239 QByteArray qba(buffers.takeFirst());-
240-
241 qba.reserve(0); // avoid that resizing needlessly reallocates-
242 if (tailBuffer == 0) {
tailBuffer == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QRingBuffer
1-2
243 qba.resize(tail);-
244 tail = 0;-
245 buffers.append(QByteArray());-
246 } else {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QRingBuffer
1
247 --tailBuffer;-
248 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
2
249 qba.remove(0, head); // does nothing if head is 0-
250 head = 0;-
251 bufferSize -= qba.size();-
252 return qba;
executed 3 times by 1 test: return qba;
Executed by:
  • tst_QRingBuffer
3
253}-
254-
255/*!-
256 \internal-
257-
258 Peek the bytes from a specified position-
259*/-
260qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const-
261{-
262 qint64 readSoFar = 0;-
263-
264 if (pos >= 0) {
pos >= 0Description
TRUEevaluated 255 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEnever evaluated
0-255
265 pos += head;-
266 for (int i = 0; readSoFar < maxLength && i < buffers.size(); ++i) {
readSoFar < maxLengthDescription
TRUEevaluated 809 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 255 times by 1 test
Evaluated by:
  • tst_QRingBuffer
i < buffers.size()Description
TRUEevaluated 809 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEnever evaluated
0-809
267 qint64 blockLength = (i == tailBuffer ? tail : buffers[i].size());
i == tailBufferDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 786 times by 1 test
Evaluated by:
  • tst_QRingBuffer
23-786
268-
269 if (pos < blockLength) {
pos < blockLengthDescription
TRUEevaluated 259 times by 1 test
Evaluated by:
  • tst_QRingBuffer
FALSEevaluated 550 times by 1 test
Evaluated by:
  • tst_QRingBuffer
259-550
270 blockLength = qMin(blockLength - pos, maxLength - readSoFar);-
271 memcpy(data + readSoFar, buffers[i].constData() + pos, blockLength);-
272 readSoFar += blockLength;-
273 pos = 0;-
274 } else {
executed 259 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
259
275 pos -= blockLength;-
276 }
executed 550 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
550
277 }-
278 }
executed 255 times by 1 test: end of block
Executed by:
  • tst_QRingBuffer
255
279-
280 return readSoFar;
executed 255 times by 1 test: return readSoFar;
Executed by:
  • tst_QRingBuffer
255
281}-
282-
283/*!-
284 \internal-
285-
286 Append a new buffer to the end-
287*/-
288void QRingBuffer::append(const QByteArray &qba)-
289{-
290 if (tail == 0) {
tail == 0Description
TRUEevaluated 44 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
FALSEevaluated 42 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QRingBuffer
42-44
291 buffers.last() = qba;-
292 } else {
executed 44 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QRingBuffer
44
293 buffers.last().resize(tail);-
294 buffers.append(qba);-
295 ++tailBuffer;-
296 }
executed 42 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QRingBuffer
42
297 tail = qba.size();-
298 bufferSize += tail;-
299}
executed 86 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QRingBuffer
86
300-
301qint64 QRingBuffer::readLine(char *data, qint64 maxLength)-
302{-
303 if (!data || --maxLength <= 0)
!dataDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QRingBuffer
--maxLength <= 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QRingBuffer
0-3
304 return -1;
never executed: return -1;
0
305-
306 qint64 i = indexOf('\n', maxLength);-
307 i = read(data, i >= 0 ? (i + 1) : maxLength);-
308-
309 // Terminate it.-
310 data[i] = '\0';-
311 return i;
executed 3 times by 1 test: return i;
Executed by:
  • tst_QRingBuffer
3
312}-
313-
314QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9