QFile: share some code

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 <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2019-05-29 15:16:34 +02:00
parent 4715d6db80
commit dd8131e3b2

View File

@ -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;