OSDN Git Service

always use the custom line-reading code in QFile::readLineData()
authorIvailo Monev <xakepa10@gmail.com>
Mon, 7 Aug 2023 12:53:02 +0000 (15:53 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 7 Aug 2023 12:53:02 +0000 (15:53 +0300)
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 <xakepa10@gmail.com>
src/core/io/qfile.cpp

index 03f3d1c..d46aeb1 100644 (file)
@@ -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;
 }
 
 /*!