introduce QT_BUFFSIZE

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-01-11 23:07:24 +00:00
parent 7652249aa5
commit bf349cbb86
15 changed files with 53 additions and 68 deletions

View file

@ -196,4 +196,6 @@
#define QT_VSNPRINTF ::vsnprintf
#endif
#define QT_BUFFSIZE BUFSIZ
#endif // include guard

View file

@ -38,6 +38,7 @@
#include "qbuffer.h"
#include "qstring.h"
#include "qendian.h"
#include "qplatformdefs.h"
#include <stdio.h>
#include <ctype.h>
@ -1120,7 +1121,7 @@ int QDataStream::skipRawData(int len)
CHECK_STREAM_PRECOND(-1)
if (dev->isSequential()) {
char buf[4096];
char buf[QT_BUFFSIZE];
int sumRead = 0;
while (len > 0) {

View file

@ -47,12 +47,10 @@
QT_BEGIN_NAMESPACE
static const int QFILE_WRITEBUFFER_SIZE = 16384;
//************* QFilePrivate
QFilePrivate::QFilePrivate()
: fileEngine(0), lastWasWrite(false),
writeBuffer(QFILE_WRITEBUFFER_SIZE), error(QFile::NoError),
writeBuffer(QT_BUFFSIZE), error(QFile::NoError),
cachedSize(0)
{
}
@ -628,7 +626,7 @@ QFile::rename(const QString &newName)
if (open(QIODevice::ReadOnly)) {
if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
bool error = false;
char block[4096];
char block[QT_BUFFSIZE];
qint64 bytes;
while ((bytes = read(block, sizeof(block))) > 0) {
if (bytes != out.write(block, bytes)) {
@ -1383,7 +1381,7 @@ bool QFilePrivate::putCharHelper(char c)
// Cutoff for code that doesn't only touch the buffer.
int writeBufferSize = writeBuffer.size();
if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QFILE_WRITEBUFFER_SIZE) {
if ((openMode & QIODevice::Unbuffered) || writeBufferSize + 1 >= QT_BUFFSIZE) {
return QIODevicePrivate::putCharHelper(c);
}
@ -1428,14 +1426,14 @@ QFile::writeData(const char *data, qint64 len)
bool buffered = !(d->openMode & Unbuffered);
// Flush buffered data if this read will overflow.
if (buffered && (d->writeBuffer.size() + len) > QFILE_WRITEBUFFER_SIZE) {
if (buffered && (d->writeBuffer.size() + len) > QT_BUFFSIZE) {
if (!flush())
return -1;
}
// Write directly to the engine if the block size is larger than
// the write buffer size.
if (!buffered || len > QFILE_WRITEBUFFER_SIZE) {
if (!buffered || len > QT_BUFFSIZE) {
qint64 ret = d->fileEngine->write(data, len);
if(ret < 0) {
QFile::FileError err = d->fileEngine->error();

View file

@ -49,14 +49,14 @@
#include "QtCore/qbytearray.h"
#include "QtCore/qobjectdefs.h"
#include "QtCore/qstring.h"
#include "QtCore/qplatformdefs.h"
#ifndef QT_NO_QOBJECT
#include "qobject_p.h"
#endif
QT_BEGIN_NAMESPACE
// BUFSIZ is defined in stdio.h
#define QIODEVICE_BUFFERSIZE qint64(BUFSIZ)
#define QIODEVICE_BUFFERSIZE qint64(QT_BUFFSIZE)
// This is QIODevice's read buffer, optimized for read(), isEmpty() and getChar()
class QIODevicePrivateLinearBuffer

View file

@ -32,7 +32,6 @@
****************************************************************************/
//#define QTEXTSTREAM_DEBUG
static const int QTEXTSTREAM_BUFFERSIZE = 16384;
/*!
\class QTextStream
@ -220,6 +219,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384;
#include "qbuffer.h"
#include "qfile.h"
#include "qnumeric.h"
#include "qplatformdefs.h"
#include "qlocale_p.h"
#ifndef QT_NO_TEXTCODEC
#include "qtextcodec.h"
@ -503,8 +503,8 @@ bool QTextStreamPrivate::fillReadBuffer(qint64 maxBytes)
device->setTextModeEnabled(false);
// read raw data into a temporary buffer
if (maxBytes < 1 || maxBytes > QTEXTSTREAM_BUFFERSIZE)
maxBytes = QTEXTSTREAM_BUFFERSIZE;
if (maxBytes < 1 || maxBytes > QT_BUFFSIZE)
maxBytes = QT_BUFFSIZE;
const QByteArray buffer = device->read(maxBytes);
int bytesRead = buffer.size();
@ -808,7 +808,7 @@ inline void QTextStreamPrivate::consume(int size)
readBufferOffset = 0;
readBuffer.clear();
saveConverterState(device->pos());
} else if (readBufferOffset > QTEXTSTREAM_BUFFERSIZE) {
} else if (readBufferOffset > QT_BUFFSIZE) {
readBuffer = readBuffer.remove(0,readBufferOffset);
readConverterSavedStateOffset += readBufferOffset;
readBufferOffset = 0;
@ -856,7 +856,7 @@ inline void QTextStreamPrivate::write(const QString &data)
string->append(data);
} else {
writeBuffer += data;
if (writeBuffer.size() > QTEXTSTREAM_BUFFERSIZE)
if (writeBuffer.size() > QT_BUFFSIZE)
flushWriteBuffer();
}
}

View file

@ -45,14 +45,15 @@
// We mean it.
//
#include <QtCore/qbytearray.h>
#include "qbytearray.h"
#include "qplatformdefs.h"
QT_BEGIN_NAMESPACE
class QRingBuffer
{
public:
inline QRingBuffer(int growth = 4096) : basicBlockSize(growth) {
inline QRingBuffer(int growth = QT_BUFFSIZE) : basicBlockSize(growth) {
buffers << QByteArray();
clear();
}

View file

@ -36,6 +36,7 @@
#include "qimage.h"
#include "qiodevice.h"
#include "qvariant.h"
#include "qplatformdefs.h"
QT_BEGIN_NAMESPACE
@ -678,8 +679,7 @@ void QGIFFormat::scan(QIODevice *device, QVector<QSize> *imageSizes, int *loopCo
uchar hold[16];
State state = Header;
const int readBufferSize = 40960; // 40k read buffer
QByteArray readBuffer(device->read(readBufferSize));
QByteArray readBuffer(device->read(QT_BUFFSIZE));
if (readBuffer.isEmpty()) {
device->seek(oldPos);
@ -912,7 +912,7 @@ void QGIFFormat::scan(QIODevice *device, QVector<QSize> *imageSizes, int *loopCo
return;
}
}
readBuffer = device->read(readBufferSize);
readBuffer = device->read(QT_BUFFSIZE);
}
device->seek(oldPos);
return;
@ -1053,11 +1053,9 @@ QGifHandler::~QGifHandler()
bool QGifHandler::imageIsComing() const
{
const int GifChunkSize = 4096;
while (!gifFormat->partialNewFrame) {
if (buffer.isEmpty()) {
buffer += device()->read(GifChunkSize);
buffer += device()->read(QT_BUFFSIZE);
if (buffer.isEmpty())
break;
}
@ -1097,11 +1095,9 @@ bool QGifHandler::canRead(QIODevice *device)
bool QGifHandler::read(QImage *image)
{
const int GifChunkSize = 4096;
while (!gifFormat->newFrame) {
if (buffer.isEmpty()) {
buffer += device()->read(GifChunkSize);
buffer += device()->read(QT_BUFFSIZE);
if (buffer.isEmpty())
break;
}

View file

@ -37,6 +37,7 @@
#include "qvariant.h"
#include "qvector.h"
#include "qbuffer.h"
#include "qplatformdefs.h"
#include <stdio.h> // jpeglib needs this to be pre-included
#include <setjmp.h>
@ -96,12 +97,10 @@ static void my_error_exit (j_common_ptr cinfo)
#endif
static const int max_buf = 4096;
struct my_jpeg_source_mgr : public jpeg_source_mgr {
// Nothing dynamic - cannot rely on destruction over longjump
QIODevice *device;
JOCTET buffer[max_buf];
JOCTET buffer[QT_BUFFSIZE];
const QBuffer *memDevice;
public:
@ -126,7 +125,7 @@ static boolean qt_fill_input_buffer(j_decompress_ptr cinfo)
src->device->seek(src->memDevice->data().size());
} else {
src->next_input_byte = src->buffer;
num_read = src->device->read((char*)src->buffer, max_buf);
num_read = src->device->read((char*)src->buffer, QT_BUFFSIZE);
}
if (num_read <= 0) {
// Insert a fake EOI marker - as per jpeglib recommendation
@ -439,7 +438,7 @@ static bool read_jpeg_image(QImage *outImage,
struct my_jpeg_destination_mgr : public jpeg_destination_mgr {
// Nothing dynamic - cannot rely on destruction over longjump
QIODevice *device;
JOCTET buffer[max_buf];
JOCTET buffer[QT_BUFFSIZE];
public:
my_jpeg_destination_mgr(QIODevice *);
@ -458,12 +457,12 @@ static boolean qt_empty_output_buffer(j_compress_ptr cinfo)
{
my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest;
int written = dest->device->write((char*)dest->buffer, max_buf);
int written = dest->device->write((char*)dest->buffer, QT_BUFFSIZE);
if (written == -1)
(*cinfo->err->error_exit)((j_common_ptr)cinfo);
dest->next_output_byte = dest->buffer;
dest->free_in_buffer = max_buf;
dest->free_in_buffer = QT_BUFFSIZE;
return TRUE;
}
@ -471,7 +470,7 @@ static boolean qt_empty_output_buffer(j_compress_ptr cinfo)
static void qt_term_destination(j_compress_ptr cinfo)
{
my_jpeg_destination_mgr* dest = (my_jpeg_destination_mgr*)cinfo->dest;
qint64 n = max_buf - dest->free_in_buffer;
qint64 n = QT_BUFFSIZE - dest->free_in_buffer;
qint64 written = dest->device->write((char*)dest->buffer, n);
if (written == -1)
@ -489,7 +488,7 @@ inline my_jpeg_destination_mgr::my_jpeg_destination_mgr(QIODevice *device)
jpeg_destination_mgr::term_destination = qt_term_destination;
this->device = device;
next_output_byte = buffer;
free_in_buffer = max_buf;
free_in_buffer = QT_BUFFSIZE;
}

View file

@ -635,7 +635,7 @@ bool QHttpNetworkConnectionChannel::expand(bool dataComplete)
Q_ASSERT(reply);
qint64 total = reply->d_func()->compressedData.size();
if (total >= CHUNK || dataComplete) {
if (total >= QT_BUFFSIZE || dataComplete) {
// uncompress the data
QByteArray content, inflated;
content = reply->d_func()->compressedData;

View file

@ -427,7 +427,7 @@ int QHttpNetworkReplyPrivate::gunzipBodyPartially(QByteArray &compressed, QByteA
{
int ret = Z_DATA_ERROR;
unsigned have;
unsigned char out[CHUNK];
unsigned char out[QT_BUFFSIZE];
int pos = -1;
if (!initInflate) {

View file

@ -55,7 +55,6 @@ static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header
#define ORIG_NAME 0x08 // bit 3 set: original file name present
#define COMMENT 0x10 // bit 4 set: file comment present
#define RESERVED 0xE0 // bits 5..7: reserved
#define CHUNK 16384
#include <QtNetwork/qtcpsocket.h>
// it's safe to include these even if SSL support is not enabled

View file

@ -40,11 +40,6 @@ QT_BEGIN_NAMESPACE
#ifdef QT_BUILD_INTERNAL
enum {
ReadBufferSize = 16384,
WriteBufferSize = ReadBufferSize
};
QNetworkAccessBackend *
QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation op,
const QNetworkRequest &request) const
@ -81,7 +76,7 @@ QNetworkAccessDebugPipeBackend::~QNetworkAccessDebugPipeBackend()
void QNetworkAccessDebugPipeBackend::open()
{
socket.connectToHost(url().host(), url().port(12345));
socket.setReadBufferSize(ReadBufferSize);
socket.setReadBufferSize(QT_BUFFSIZE);
// socket ready read -> we can push from socket to downstream
connect(&socket, SIGNAL(readyRead()), SLOT(socketReadyRead()));
@ -132,8 +127,8 @@ void QNetworkAccessDebugPipeBackend::pushFromSocketToDownstream()
if (hasDownloadFinished)
return;
buffer.resize(ReadBufferSize);
qint64 haveRead = socket.read(buffer.data(), ReadBufferSize);
buffer.resize(QT_BUFFSIZE);
qint64 haveRead = socket.read(buffer.data(), QT_BUFFSIZE);
if (haveRead == -1) {
hasDownloadFinished = true;
@ -164,11 +159,11 @@ void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()
return;
forever {
if (socket.bytesToWrite() >= WriteBufferSize)
if (socket.bytesToWrite() >= QT_BUFFSIZE)
return;
qint64 haveRead;
const char *readPointer = uploadByteDevice->readPointer(WriteBufferSize, haveRead);
const char *readPointer = uploadByteDevice->readPointer(QT_BUFFSIZE, haveRead);
if (haveRead == -1) {
// EOF
hasUploadFinished = true;

View file

@ -37,7 +37,7 @@
#include "qsvghandler_p.h"
#include "qsvgfont_p.h"
#include "qplatformdefs.h"
#include "qpainter.h"
#include "qfile.h"
#include "qbuffer.h"
@ -74,7 +74,6 @@ static QByteArray qt_inflateGZipDataFrom(QIODevice *device)
Q_ASSERT(device->isOpen() && device->isReadable());
static const int CHUNK_SIZE = 4096;
int zlibResult = Z_OK;
QByteArray source;
@ -100,7 +99,7 @@ static QByteArray qt_inflateGZipDataFrom(QIODevice *device)
while (stillMoreWorkToDo) {
if (!zlibStream.avail_in) {
source = device->read(CHUNK_SIZE);
source = device->read(QT_BUFFSIZE);
if (source.isEmpty())
break;
@ -112,10 +111,10 @@ static QByteArray qt_inflateGZipDataFrom(QIODevice *device)
do {
// Prepare the destination buffer
int oldSize = destination.size();
destination.resize(oldSize + CHUNK_SIZE);
destination.resize(oldSize + QT_BUFFSIZE);
zlibStream.next_out = reinterpret_cast<Bytef*>(
destination.data() + oldSize - zlibStream.avail_out);
zlibStream.avail_out += CHUNK_SIZE;
zlibStream.avail_out += QT_BUFFSIZE;
zlibResult = inflate(&zlibStream, Z_NO_FLUSH);
switch (zlibResult) {

View file

@ -31,12 +31,7 @@
**
****************************************************************************/
// Just to get Q_OS_SYMBIAN
#include <qglobal.h>
#include <QtTest/QtTest>
#include <qcoreapplication.h>
#include <qtcpsocket.h>
#include <qtcpserver.h>
@ -45,12 +40,11 @@
#include <qstringlist.h>
#include <qplatformdefs.h>
#include <qhostinfo.h>
#include <QNetworkConfiguration>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
#include <QNetworkProxy>
Q_DECLARE_METATYPE(QNetworkProxy)
Q_DECLARE_METATYPE(QList<QNetworkProxy>)
@ -157,7 +151,7 @@ void tst_QTcpServer::ipv4LoopbackPerformanceTest()
QTcpSocket *clientB = server.nextPendingConnection();
QVERIFY(clientB);
QByteArray buffer(16384, '@');
QByteArray buffer(QT_BUFFSIZE, '@');
QTime stopWatch;
stopWatch.start();
qlonglong totalWritten = 0;
@ -166,7 +160,7 @@ void tst_QTcpServer::ipv4LoopbackPerformanceTest()
clientA.flush();
totalWritten += buffer.size();
while (clientB->waitForReadyRead(100)) {
if (clientB->bytesAvailable() == 16384)
if (clientB->bytesAvailable() == QT_BUFFSIZE)
break;
}
clientB->read(buffer.data(), buffer.size());
@ -174,7 +168,7 @@ void tst_QTcpServer::ipv4LoopbackPerformanceTest()
clientB->flush();
totalWritten += buffer.size();
while (clientA.waitForReadyRead(100)) {
if (clientA.bytesAvailable() == 16384)
if (clientA.bytesAvailable() == QT_BUFFSIZE)
break;
}
clientA.read(buffer.data(), buffer.size());
@ -211,7 +205,7 @@ void tst_QTcpServer::ipv6LoopbackPerformanceTest()
QTcpSocket *clientB = server.nextPendingConnection();
QVERIFY(clientB);
QByteArray buffer(16384, '@');
QByteArray buffer(QT_BUFFSIZE, '@');
QTime stopWatch;
stopWatch.start();
qlonglong totalWritten = 0;
@ -220,7 +214,7 @@ void tst_QTcpServer::ipv6LoopbackPerformanceTest()
clientA.flush();
totalWritten += buffer.size();
while (clientB->waitForReadyRead(100)) {
if (clientB->bytesAvailable() == 16384)
if (clientB->bytesAvailable() == QT_BUFFSIZE)
break;
}
clientB->read(buffer.data(), buffer.size());
@ -228,7 +222,7 @@ void tst_QTcpServer::ipv6LoopbackPerformanceTest()
clientB->flush();
totalWritten += buffer.size();
while (clientA.waitForReadyRead(100)) {
if (clientA.bytesAvailable() == 16384)
if (clientA.bytesAvailable() == QT_BUFFSIZE)
break;
}
clientA.read(buffer.data(), buffer.size());
@ -266,7 +260,7 @@ void tst_QTcpServer::ipv4PerformanceTest()
QTcpSocket *clientB = server.nextPendingConnection();
QVERIFY(clientB);
QByteArray buffer(16384, '@');
QByteArray buffer(QT_BUFFSIZE, '@');
QTime stopWatch;
stopWatch.start();
qlonglong totalWritten = 0;

View file

@ -37,6 +37,7 @@
#include <qstring.h>
#include <qtextstream.h>
#include <qdebug.h>
#include <qplatformdefs.h>
#include <limits.h>
#include <stdio.h>
@ -113,7 +114,7 @@ void check(const QString &fileName)
QStringList lines;
bool found = false;
while (true) {
QByteArray bline = file.readLine(16384);
QByteArray bline = file.readLine(QT_BUFFSIZE);
if (bline.isEmpty())
break;
QString line = QString::fromLocal8Bit(bline);