From 7c840afcb12096778ecb1539f7baba3e02ba6f85 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 7 Aug 2023 15:53:02 +0300 Subject: [PATCH] always use the custom line-reading code in QFile::readLineData() sequential or not read() is read(), positioning should be done before that. it is also faster than calling QFile::readData() multiple times which was done for non-sequential files (regular files) Signed-off-by: Ivailo Monev --- src/core/io/qfile.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/core/io/qfile.cpp b/src/core/io/qfile.cpp index 03f3d1cc1..d46aeb105 100644 --- a/src/core/io/qfile.cpp +++ b/src/core/io/qfile.cpp @@ -1261,23 +1261,18 @@ bool QFile::seek(qint64 off) qint64 QFile::readLineData(char *data, qint64 maxlen) { Q_D(QFile); - if (d->fd != -1 && isSequential()) { - qint64 readSoFar = 0; - while (readSoFar < maxlen) { - char c; - qint64 readResult = qt_safe_read(d->fd, &c, 1); - if (readResult <= 0) - return (readSoFar > 0) ? readSoFar : -1; - ++readSoFar; - *data++ = c; - if (c == '\n') - return readSoFar; - } - return readSoFar; + qint64 readSoFar = 0; + while (readSoFar < maxlen) { + char c; + qint64 readResult = qt_safe_read(d->fd, &c, 1); + if (readResult <= 0) + return (readSoFar > 0) ? readSoFar : -1; + ++readSoFar; + *data++ = c; + if (c == '\n') + return readSoFar; } - // Fall back to QIODevice's readLine implementation if the engine - // cannot do it faster. - return QIODevice::readLineData(data, maxlen); + return readSoFar; } /*! -- 2.11.0