From dd8131e3b25a4ac60eb55022b69b374f0b9a476c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 29 May 2019 15:16:34 +0200 Subject: QFile: share some code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pack four qWarning() calls into a separate cold function. Use qUtf16Printable(). Saves >600b in text size on optimized AMD64 Linux GCC 9.1 builds. Change-Id: Ib25ea473d1d77faaecaf8750726c83675d87279e Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qfile.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 37de4450cc..13af113da1 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -61,6 +61,12 @@ QT_BEGIN_NAMESPACE +Q_DECL_COLD_FUNCTION +static bool file_already_open(QFile &file, const char *where = nullptr) { + qWarning("QFile::%s: File (%ls) already open", where ? where : "open", qUtf16Printable(file.fileName())); + return false; +} + //************* QFilePrivate QFilePrivate::QFilePrivate() { @@ -324,8 +330,7 @@ QFile::setFileName(const QString &name) { Q_D(QFile); if (isOpen()) { - qWarning("QFile::setFileName: File (%s) is already opened", - qPrintable(fileName())); + file_already_open(*this, "setFileName"); close(); } if(d->fileEngine) { //get a new file engine later @@ -910,10 +915,8 @@ QFile::copy(const QString &fileName, const QString &newName) bool QFile::open(OpenMode mode) { Q_D(QFile); - if (isOpen()) { - qWarning("QFile::open: File (%s) already open", qPrintable(fileName())); - return false; - } + if (isOpen()) + return file_already_open(*this); // Either Append or NewOnly implies WriteOnly if (mode & (Append | NewOnly)) mode |= WriteOnly; @@ -982,10 +985,8 @@ bool QFile::open(OpenMode mode) bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags) { Q_D(QFile); - if (isOpen()) { - qWarning("QFile::open: File (%s) already open", qPrintable(fileName())); - return false; - } + if (isOpen()) + return file_already_open(*this); // Either Append or NewOnly implies WriteOnly if (mode & (Append | NewOnly)) mode |= WriteOnly; @@ -1041,10 +1042,8 @@ bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags) bool QFile::open(int fd, OpenMode mode, FileHandleFlags handleFlags) { Q_D(QFile); - if (isOpen()) { - qWarning("QFile::open: File (%s) already open", qPrintable(fileName())); - return false; - } + if (isOpen()) + return file_already_open(*this); // Either Append or NewOnly implies WriteOnly if (mode & (Append | NewOnly)) mode |= WriteOnly; -- cgit v1.2.3