diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2014-10-30 19:34:19 +0400 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2015-01-23 14:36:27 +0100 |
commit | de71c8a6f827b7ac1a0c394a92c113edbe6d5df7 (patch) | |
tree | a3277fdca976010dfaa8ec98f5af290430008be9 /src/corelib/io/qtextstream.h | |
parent | 0192630f55bb62bd7cf3a1dc29c6c0624ca7759c (diff) |
Add QTextStream::readLine() overload
The most common use case for QTextStream::readLine() is reading
a file line by line in a loop. The existing readLine() method
allocates new memory for each line, that results in a loss of
speed. The introduced overload can use already allocated memory.
Besides it allows you to not think about filesystem specifics.
The current QFile documentation suggests a separate way to read
files from /proc filesystem. With this overload it's possible
to use the same idiom in all cases:
QTextStream in(&file);
QString line;
while (in.readLine(&line)) {
process_line(line);
}
The idea was inspired by the blog post of Ivan Čukić:
http://ivan.fomentgroup.org/blog/2014/10/03/api-design-and-impact-on-the-performance-qt-vs-stl-example/
Change-Id: I0c62b4a52681870589bc099905e83ed69e03dd40
Reviewed-by: Martin Smith <martin.smith@digia.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/io/qtextstream.h')
-rw-r--r-- | src/corelib/io/qtextstream.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/corelib/io/qtextstream.h b/src/corelib/io/qtextstream.h index b15e7772e2..6f5e2473e4 100644 --- a/src/corelib/io/qtextstream.h +++ b/src/corelib/io/qtextstream.h @@ -124,6 +124,7 @@ public: void skipWhiteSpace(); QString readLine(qint64 maxlen = 0); + bool readLine(QString *line, qint64 maxlen = 0); QString readAll(); QString read(qint64 maxlen); |