diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-10-24 22:31:27 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-05-03 04:35:06 +0000 |
commit | 5a76a3fb03f8d1dc8cb367de1a1dc6a37048376a (patch) | |
tree | 2328d894da121bd0912cb9777f6254cc62296946 /src/gui | |
parent | 0eaac0a3a95f8a74c06d062d3aa7928cbb09d493 (diff) |
QtBase: use printf-style qWarning/qDebug where possible (II)
The printf-style version of QDebug expands to a lot less code than the
std::ostream-style version. Of course, you pay in type safety (but
compilers warn about it these days), you cannot stream complex Qt
types and streaming QStrings is awkward, but in many cases you
actually improve on readability.
But the main reason is that something that's not supposed to be
executed under normal operation has no business bloating executable
code size.
This is not an attempt at converting all qWarnings() to printf-style,
only the low-hanging fruit.
In this second part, replace
qWarning() << "" << non-QString
with
qWarning("..%.", non-QString).
QString (and QUrl etc) have special escaping handling when streamed
into QDebug, so leave those alone. They also seem to expand to less
code than the qPrintable() alternative, so there's no reason to
replace them.
Saves 2KiB, 3.4KiB, ~750b and ~450b in text size in QtCore, Gui,
Network and Widgets, resp., on optimized GCC 5.3 AMD64 builds.
Change-Id: Iae6823e543544347e628ca1060d6d51e3b04d3f4
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qimagereader.cpp | 4 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 9 | ||||
-rw-r--r-- | src/gui/opengl/qopenglengineshadermanager.cpp | 4 | ||||
-rw-r--r-- | src/gui/opengl/qopenglshaderprogram.cpp | 17 |
5 files changed, 18 insertions, 18 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 8bf0ce3523..dd1f0c8943 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -450,8 +450,8 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, if (handler) { #ifdef QIMAGEREADER_DEBUG - qDebug() << "QImageReader::createReadHandler: the" << _qt_BuiltInFormats[currentFormat].extension - << "built-in handler can read this data"; + qDebug("QImageReader::createReadHandler: the %s built-in handler can read this data", + _qt_BuiltInFormats[currentFormat].extension); #endif break; } diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 129e93db8d..1f102dcec5 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1186,7 +1186,7 @@ static void init_plugins(const QList<QByteArray> &pluginList) if (plugin) QGuiApplicationPrivate::generic_plugin_list.append(plugin); else - qWarning() << "No such plugin for spec " << pluginSpec; + qWarning("No such plugin for spec \"%s\"", pluginSpec.constData()); } } diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 4cc9e95e81..d6e467db59 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -68,10 +68,11 @@ static inline qreal initialGlobalScaleFactor() } } else { if (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar)) { - qWarning() << "Warning:" << legacyDevicePixelEnvVar << "is deprecated. Instead use:" << endl - << " " << autoScreenEnvVar << "to enable platform plugin controlled per-screen factors." << endl - << " " << screenFactorsEnvVar << "to set per-screen factors." << endl - << " " << scaleFactorEnvVar << "to set the application global scale factor."; + qWarning("Warning: %s is deprecated. Instead use:\n" + " %s to enable platform plugin controlled per-screen factors.\n" + " %s to set per-screen factors.\n" + " %s to set the application global scale factor.", + legacyDevicePixelEnvVar, autoScreenEnvVar, screenFactorsEnvVar, scaleFactorEnvVar); int dpr = qEnvironmentVariableIntValue(legacyDevicePixelEnvVar); if (dpr > 0) diff --git a/src/gui/opengl/qopenglengineshadermanager.cpp b/src/gui/opengl/qopenglengineshadermanager.cpp index 4e3d14ba37..1d3e47f93b 100644 --- a/src/gui/opengl/qopenglengineshadermanager.cpp +++ b/src/gui/opengl/qopenglengineshadermanager.cpp @@ -390,7 +390,7 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO fragShader->setObjectName(QString::fromLatin1(description)); #endif if (!fragShader->compileSourceCode(fragSource)) { - qWarning() << "Warning:" << description << "failed to compile!"; + qWarning("Warning: \"%s\" failed to compile!", description.constData()); break; } @@ -405,7 +405,7 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO vertexShader->setObjectName(QString::fromLatin1(description)); #endif if (!vertexShader->compileSourceCode(vertexSource)) { - qWarning() << "Warning:" << description << "failed to compile!"; + qWarning("Warning: \"%s\" failed to compile!", description.constData()); break; } diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp index 4134513210..f076e10e20 100644 --- a/src/gui/opengl/qopenglshaderprogram.cpp +++ b/src/gui/opengl/qopenglshaderprogram.cpp @@ -337,9 +337,10 @@ bool QOpenGLShaderPrivate::compile(QOpenGLShader *q) // Dump the source code if we got it if (sourceCodeBuffer) { - qWarning("*** Problematic %s shader source code ***", type); - qWarning() << qPrintable(QString::fromLatin1(sourceCodeBuffer)); - qWarning("***"); + qWarning("*** Problematic %s shader source code ***\n" + "%ls\n" + "***", + type, qUtf16Printable(QString::fromLatin1(sourceCodeBuffer))); } // Cleanup @@ -1215,8 +1216,7 @@ int QOpenGLShaderProgram::attributeLocation(const char *name) const if (d->linked && d->programGuard && d->programGuard->id()) { return d->glfuncs->glGetAttribLocation(d->programGuard->id(), name); } else { - qWarning() << "QOpenGLShaderProgram::attributeLocation(" << name - << "): shader program is not linked"; + qWarning("QOpenGLShaderProgram::attributeLocation(%s): shader program is not linked", name); return -1; } } @@ -1479,7 +1479,7 @@ void QOpenGLShaderProgram::setAttributeValue Q_D(QOpenGLShaderProgram); Q_UNUSED(d); if (rows < 1 || rows > 4) { - qWarning() << "QOpenGLShaderProgram::setAttributeValue: rows" << rows << "not supported"; + qWarning("QOpenGLShaderProgram::setAttributeValue: rows %d not supported", rows); return; } if (location != -1) { @@ -1891,8 +1891,7 @@ int QOpenGLShaderProgram::uniformLocation(const char *name) const if (d->linked && d->programGuard && d->programGuard->id()) { return d->glfuncs->glGetUniformLocation(d->programGuard->id(), name); } else { - qWarning() << "QOpenGLShaderProgram::uniformLocation(" << name - << "): shader program is not linked"; + qWarning("QOpenGLShaderProgram::uniformLocation(%s): shader program is not linked", name); return -1; } } @@ -2819,7 +2818,7 @@ void QOpenGLShaderProgram::setUniformValueArray(int location, const GLfloat *val else if (tupleSize == 4) d->glfuncs->glUniform4fv(location, count, values); else - qWarning() << "QOpenGLShaderProgram::setUniformValue: size" << tupleSize << "not supported"; + qWarning("QOpenGLShaderProgram::setUniformValue: size %d not supported", tupleSize); } } |