QtGui: use printf-style qWarning/qDebug where possible (I)

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 first part, replace
   qWarning() << "...";
with
   qWarning("...");

In QTransform shared warning strings.

Saves 3KiB in text size on optimized GCC 5.3 AMD64 builds.

Change-Id: I142a8020eaab043d78465178192f2c8c6d1cc4f9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
bb10
Marc Mutz 2015-10-17 17:48:34 +02:00
parent b6b3803b21
commit 600529e07a
21 changed files with 55 additions and 47 deletions

View File

@ -505,7 +505,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
if (!handler) {
#ifdef QIMAGEREADER_DEBUG
qDebug() << "QImageReader::createReadHandler: no handlers found. giving up.";
qDebug("QImageReader::createReadHandler: no handlers found. giving up.");
#endif
// no handler: give up.
return 0;

View File

@ -91,7 +91,7 @@ bool QPicturePaintEngine::begin(QPaintDevice *pd)
{
Q_D(QPicturePaintEngine);
#ifdef QT_PICTURE_DEBUG
qDebug() << "QPicturePaintEngine::begin()";
qDebug("QPicturePaintEngine::begin()");
#endif
Q_ASSERT(pd);
QPicture *pic = static_cast<QPicture *>(pd);
@ -124,7 +124,7 @@ bool QPicturePaintEngine::end()
{
Q_D(QPicturePaintEngine);
#ifdef QT_PICTURE_DEBUG
qDebug() << "QPicturePaintEngine::end()";
qDebug("QPicturePaintEngine::end()");
#endif
d->pic_d->trecs++;
d->s << (quint8) QPicturePrivate::PdcEnd << (quint8) 0;

View File

@ -3009,7 +3009,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const
itemsSet << item;
stack.push(item);
} else {
qWarning() << "QStandardItemModel::mimeData: No item associated with invalid index";
qWarning("QStandardItemModel::mimeData: No item associated with invalid index");
return 0;
}
}

View File

@ -1437,7 +1437,7 @@ void QGuiApplicationPrivate::init()
typedef void (*TasInitialize)(void);
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
if (Q_UNLIKELY(!initFunction)) {
qCritical() << "Library qttestability resolve failed!";
qCritical("Library qttestability resolve failed!");
} else {
initFunction();
}
@ -1595,7 +1595,7 @@ QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function)
{
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
if (!pi) {
qWarning() << "QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function";
qWarning("QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
return Q_NULLPTR;
}

View File

@ -1033,19 +1033,19 @@ void QOpenGLContext::swapBuffers(QSurface *surface)
return;
if (!surface) {
qWarning() << "QOpenGLContext::swapBuffers() called with null argument";
qWarning("QOpenGLContext::swapBuffers() called with null argument");
return;
}
if (!surface->supportsOpenGL()) {
qWarning() << "QOpenGLContext::swapBuffers() called with non-opengl surface";
qWarning("QOpenGLContext::swapBuffers() called with non-opengl surface");
return;
}
if (surface->surfaceClass() == QSurface::Window
&& !qt_window_private(static_cast<QWindow *>(surface))->receivedExpose)
{
qWarning() << "QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined";
qWarning("QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined");
}
QPlatformSurface *surfaceHandle = surface->surfaceHandle();
@ -1054,7 +1054,7 @@ void QOpenGLContext::swapBuffers(QSurface *surface)
#if !defined(QT_NO_DEBUG)
if (!QOpenGLContextPrivate::toggleMakeCurrentTracker(this, false))
qWarning() << "QOpenGLContext::swapBuffers() called without corresponding makeCurrent()";
qWarning("QOpenGLContext::swapBuffers() called without corresponding makeCurrent()");
#endif
if (surface->format().swapBehavior() == QSurfaceFormat::SingleBuffer)
functions()->glFlush();

View File

@ -54,7 +54,7 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th,
QPlatformIntegration::StyleHint ih)
{
if (!QCoreApplication::instance()) {
qWarning() << "Must construct a QGuiApplication before accessing a platform theme hint.";
qWarning("Must construct a QGuiApplication before accessing a platform theme hint.");
return QVariant();
}
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {

View File

@ -1145,7 +1145,7 @@ qreal QWindow::devicePixelRatio() const
void QWindow::setWindowState(Qt::WindowState state)
{
if (state == Qt::WindowActive) {
qWarning() << "QWindow::setWindowState does not accept Qt::WindowActive";
qWarning("QWindow::setWindowState does not accept Qt::WindowActive");
return;
}
@ -2436,7 +2436,7 @@ QWindow *QWindowPrivate::topLevelWindow() const
QWindow *QWindow::fromWinId(WId id)
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
qWarning() << "QWindow::fromWinId(): platform plugin does not support foreign windows.";
qWarning("QWindow::fromWinId(): platform plugin does not support foreign windows.");
return 0;
}

View File

@ -273,7 +273,7 @@ QOpenGLFunctions::QOpenGLFunctions(QOpenGLContext *context)
if (context && QOpenGLContextGroup::currentContextGroup() == context->shareGroup())
d_ptr = qt_gl_functions(context);
else
qWarning() << "QOpenGLFunctions created with non-current context";
qWarning("QOpenGLFunctions created with non-current context");
}
QOpenGLExtensions::QOpenGLExtensions()

View File

@ -250,7 +250,7 @@ bool QOpenGLShaderPrivate::create()
shader = glfuncs->glCreateShader(GL_FRAGMENT_SHADER);
}
if (!shader) {
qWarning() << "QOpenGLShader: could not create shader";
qWarning("QOpenGLShader: could not create shader");
return false;
}
shaderGuard = new QOpenGLSharedResourceGuard(context, shader, freeShaderFunc);
@ -798,7 +798,7 @@ bool QOpenGLShaderProgram::init()
GLuint program = d->glfuncs->glCreateProgram();
if (!program) {
qWarning() << "QOpenGLShaderProgram: could not create shader program";
qWarning("QOpenGLShaderProgram: could not create shader program");
return false;
}
if (d->programGuard)

View File

@ -1163,7 +1163,7 @@ void QRasterPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
if (s->matrix.type() <= QTransform::TxScale
&& path.isRect()) {
#ifdef QT_DEBUG_DRAW
qDebug() << " --- optimizing vector clip to rect clip...";
qDebug(" --- optimizing vector clip to rect clip...");
#endif
const qreal *points = path.points();
QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]);

View File

@ -1951,7 +1951,7 @@ int QPdfEnginePrivate::writeImage(const QByteArray &data, int width, int height,
xprintf("/Interpolate true\n");
int len = 0;
if (dct) {
//qDebug() << "DCT";
//qDebug("DCT");
xprintf("/Filter /DCTDecode\n>>\nstream\n");
write(data);
len = data.length();
@ -2215,7 +2215,7 @@ int QPdfEnginePrivate::generateGradientShader(const QGradient *gradient, const Q
return generateRadialGradientShader(static_cast<const QRadialGradient *>(gradient), matrix, alpha);
case QGradient::ConicalGradient:
default:
qWarning() << "Implement me!";
qWarning("Implement me!");
}
return 0;
}

View File

@ -53,6 +53,14 @@
QT_BEGIN_NAMESPACE
#ifndef QT_NO_DEBUG
Q_NEVER_INLINE
static void nanWarning(const char *func)
{
qWarning("QTransform::%s with NaN called", func);
}
#endif // QT_NO_DEBUG
#define Q_NEAR_CLIP (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)
#ifdef MAP
@ -418,7 +426,7 @@ QTransform &QTransform::translate(qreal dx, qreal dy)
return *this;
#ifndef QT_NO_DEBUG
if (qIsNaN(dx) | qIsNaN(dy)) {
qWarning() << "QTransform::translate with NaN called";
nanWarning("translate");
return *this;
}
#endif
@ -461,7 +469,7 @@ QTransform QTransform::fromTranslate(qreal dx, qreal dy)
{
#ifndef QT_NO_DEBUG
if (qIsNaN(dx) | qIsNaN(dy)) {
qWarning() << "QTransform::fromTranslate with NaN called";
nanWarning("fromTranslate");
return QTransform();
}
#endif
@ -486,7 +494,7 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
return *this;
#ifndef QT_NO_DEBUG
if (qIsNaN(sx) | qIsNaN(sy)) {
qWarning() << "QTransform::scale with NaN called";
nanWarning("scale");
return *this;
}
#endif
@ -527,7 +535,7 @@ QTransform QTransform::fromScale(qreal sx, qreal sy)
{
#ifndef QT_NO_DEBUG
if (qIsNaN(sx) | qIsNaN(sy)) {
qWarning() << "QTransform::fromScale with NaN called";
nanWarning("fromScale");
return QTransform();
}
#endif
@ -552,7 +560,7 @@ QTransform & QTransform::shear(qreal sh, qreal sv)
return *this;
#ifndef QT_NO_DEBUG
if (qIsNaN(sh) | qIsNaN(sv)) {
qWarning() << "QTransform::shear with NaN called";
nanWarning("shear");
return *this;
}
#endif
@ -613,7 +621,7 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
return *this;
#ifndef QT_NO_DEBUG
if (qIsNaN(a)) {
qWarning() << "QTransform::rotate with NaN called";
nanWarning("rotate");
return *this;
}
#endif
@ -704,7 +712,7 @@ QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
{
#ifndef QT_NO_DEBUG
if (qIsNaN(a)) {
qWarning() << "QTransform::rotateRadians with NaN called";
nanWarning("rotateRadians");
return *this;
}
#endif

View File

@ -246,7 +246,7 @@ QFontEngineQPF2::QFontEngineQPF2(const QFontDef &def, const QByteArray &data)
if (!verifyHeader(fontData, dataSize)) {
#if defined(DEBUG_FONTENGINE)
qDebug() << "verifyHeader failed!";
qDebug("verifyHeader failed!");
#endif
return;
}

View File

@ -798,7 +798,7 @@ static void convertPath(const QPainterPath &path, QVector<TTF_POINT> *points, QV
base -= 3;
} else {
// need to split
// qDebug() << " -> splitting";
// qDebug(" -> splitting");
qint16 a, b, c, d;
base[6].x = base[3].x;
c = base[1].x;
@ -859,7 +859,7 @@ static void getBounds(const QVector<TTF_POINT> &points, qint16 *xmin, qint16 *xm
static int convertToRelative(QVector<TTF_POINT> *points)
{
// convert points to relative and setup flags
// qDebug() << "relative points:";
// qDebug("relative points:");
qint16 prev_x = 0;
qint16 prev_y = 0;
int point_array_size = 0;
@ -980,7 +980,7 @@ static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advanc
// qDebug() << "number of contours=" << endPoints.size();
// for (int i = 0; i < points.size(); ++i)
// qDebug() << " point[" << i << "] = " << QPoint(points.at(i).x, points.at(i).y) << " flags=" << points.at(i).flags;
// qDebug() << "endPoints:";
// qDebug("endPoints:");
// for (int i = 0; i < endPoints.size(); ++i)
// qDebug() << endPoints.at(i);

View File

@ -100,7 +100,7 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *
registerFont(fontName,QString(),QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,false,writingSystems,handle);
}
} else {
qDebug() << "header verification of QPF2 font failed. maybe it is corrupt?";
qDebug("header verification of QPF2 font failed. maybe it is corrupt?");
}
}

View File

@ -1598,7 +1598,7 @@ QTextLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QT
// floats in other cells we must clear the list here.
data(t)->floats.clear();
// qDebug() << "layoutCell done";
// qDebug("layoutCell done");
return layoutStruct;
}
@ -2030,7 +2030,7 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur
// qDebug() << "have line: right=" << right << "left=" << left << "textWidth=" << currentLine->width();
if (right - left < QFixed::fromReal(currentLine->naturalTextWidth()) + fd->size.width) {
layoutStruct->pendingFloats.append(frame);
// qDebug() << " adding to pending list";
// qDebug(" adding to pending list");
return;
}
}
@ -2543,7 +2543,7 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayout
contentHasAlignment = true;
if (it.atEnd()) {
//qDebug() << "layout done!";
//qDebug("layout done!");
currentLazyLayoutPosition = -1;
QCheckPoint cp;
cp.y = layoutStruct->y;

View File

@ -271,7 +271,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document)
#ifndef QT_NO_TEXTHTMLPARSER
if (format == "html" || format == "htm") {
if (!d->device->isWritable() && ! d->device->open(QIODevice::WriteOnly)) {
qWarning() << "QTextDocumentWriter::write: the device can not be opened for writing";
qWarning("QTextDocumentWriter::write: the device can not be opened for writing");
return false;
}
QTextStream ts(d->device);
@ -285,7 +285,7 @@ bool QTextDocumentWriter::write(const QTextDocument *document)
#endif
if (format == "txt" || format == "plaintext") {
if (!d->device->isWritable() && ! d->device->open(QIODevice::WriteOnly)) {
qWarning() << "QTextDocumentWriter::write: the device can not be opened for writing";
qWarning("QTextDocumentWriter::write: the device can not be opened for writing");
return false;
}
QTextStream ts(d->device);

View File

@ -816,7 +816,7 @@ void QTextEngine::bidiReorder(int numItems, const quint8 *levels, int *visualOrd
}
#if (BIDI_DEBUG >= 1)
// qDebug() << "visual order is:";
// qDebug("visual order is:");
// for (i = 0; i < numItems; i++)
// qDebug() << visualOrder[i];
#endif

View File

@ -2976,7 +2976,7 @@ int QTextLine::xToCursor(qreal _x, CursorPosition cpos) const
}
}
// right of last item
// qDebug() << "right of last";
// qDebug("right of last");
int item = visualOrder[nItems-1]+firstItem;
QScriptItem &si = eng->layoutData->items[item];
if (!si.num_glyphs)

View File

@ -769,7 +769,7 @@ bool QTextOdfWriter::writeAll()
m_strategy = new QXmlStreamStrategy(m_device);
if (!m_device->isWritable() && ! m_device->open(QIODevice::WriteOnly)) {
qWarning() << "QTextOdfWriter::writeAll: the device can not be opened for writing";
qWarning("QTextOdfWriter::writeAll: the device can not be opened for writing");
return false;
}
QXmlStreamWriter writer(m_strategy->contentStream);

View File

@ -574,7 +574,7 @@ void QZipReaderPrivate::scanFiles()
uchar tmp[4];
device->read((char *)tmp, 4);
if (readUInt(tmp) != 0x04034b50) {
qWarning() << "QZip: not a zip file!";
qWarning("QZip: not a zip file!");
return;
}
@ -586,7 +586,7 @@ void QZipReaderPrivate::scanFiles()
while (start_of_directory == -1) {
const int pos = device->size() - int(sizeof(EndOfDirectory)) - i;
if (pos < 0 || i > 65535) {
qWarning() << "QZip: EndOfDirectory not found";
qWarning("QZip: EndOfDirectory not found");
return;
}
@ -603,7 +603,7 @@ void QZipReaderPrivate::scanFiles()
ZDEBUG("start_of_directory at %d, num_dir_entries=%d", start_of_directory, num_dir_entries);
int comment_length = readUShort(eod.comment_length);
if (comment_length != i)
qWarning() << "QZip: failed to parse zip file.";
qWarning("QZip: failed to parse zip file.");
comment = device->read(qMin(comment_length, i));
@ -612,30 +612,30 @@ void QZipReaderPrivate::scanFiles()
FileHeader header;
int read = device->read((char *) &header.h, sizeof(CentralFileHeader));
if (read < (int)sizeof(CentralFileHeader)) {
qWarning() << "QZip: Failed to read complete header, index may be incomplete";
qWarning("QZip: Failed to read complete header, index may be incomplete");
break;
}
if (readUInt(header.h.signature) != 0x02014b50) {
qWarning() << "QZip: invalid header signature, index may be incomplete";
qWarning("QZip: invalid header signature, index may be incomplete");
break;
}
int l = readUShort(header.h.file_name_length);
header.file_name = device->read(l);
if (header.file_name.length() != l) {
qWarning() << "QZip: Failed to read filename from zip index, index may be incomplete";
qWarning("QZip: Failed to read filename from zip index, index may be incomplete");
break;
}
l = readUShort(header.h.extra_field_length);
header.extra_field = device->read(l);
if (header.extra_field.length() != l) {
qWarning() << "QZip: Failed to read extra field in zip file, skipping file, index may be incomplete";
qWarning("QZip: Failed to read extra field in zip file, skipping file, index may be incomplete");
break;
}
l = readUShort(header.h.file_comment_length);
header.file_comment = device->read(l);
if (header.file_comment.length() != l) {
qWarning() << "QZip: Failed to read read file comment, index may be incomplete";
qWarning("QZip: Failed to read read file comment, index may be incomplete");
break;
}