QtCore: 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("...").

Saves ~750b in text size on optimized GCC 5.3 AMD64 builds.

Change-Id: I8bf3e46cd5a6b2cae0ceb3e355a50f61925c63d3
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
bb10
Marc Mutz 2015-10-17 17:48:34 +02:00
parent 5bc54c878f
commit 134cad32d7
15 changed files with 37 additions and 37 deletions

View File

@ -317,11 +317,11 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths)
// Autotest override case - use the explicitly selected engine only
const QStringRef forceName = on.midRef(26);
if(forceName == QLatin1String("poller")) {
qDebug() << "QFileSystemWatcher: skipping native engine, using only polling engine";
qDebug("QFileSystemWatcher: skipping native engine, using only polling engine");
d_func()->initPollerEngine();
engine = d->poller;
} else if(forceName == QLatin1String("native")) {
qDebug() << "QFileSystemWatcher: skipping polling engine, using only native engine";
qDebug("QFileSystemWatcher: skipping polling engine, using only native engine");
engine = d->native;
}
}

View File

@ -344,7 +344,7 @@ QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &path
void QInotifyFileSystemWatcherEngine::readFromInotify()
{
// qDebug() << "QInotifyFileSystemWatcherEngine::readFromInotify";
// qDebug("QInotifyFileSystemWatcherEngine::readFromInotify");
int buffSize = 0;
ioctl(inotifyFd, FIONREAD, (char *) &buffSize);

View File

@ -376,7 +376,7 @@ QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &pro
if (!proxy_index.isValid())
return QModelIndex(); // for now; we may want to be able to set a root index later
if (proxy_index.model() != q_func()) {
qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapToSource";
qWarning("QSortFilterProxyModel: index from wrong model passed to mapToSource");
Q_ASSERT(!"QSortFilterProxyModel: index from wrong model passed to mapToSource");
return QModelIndex();
}
@ -394,7 +394,7 @@ QModelIndex QSortFilterProxyModelPrivate::source_to_proxy(const QModelIndex &sou
if (!source_index.isValid())
return QModelIndex(); // for now; we may want to be able to set a root index later
if (source_index.model() != model) {
qWarning() << "QSortFilterProxyModel: index from wrong model passed to mapFromSource";
qWarning("QSortFilterProxyModel: index from wrong model passed to mapFromSource");
Q_ASSERT(!"QSortFilterProxyModel: index from wrong model passed to mapFromSource");
return QModelIndex();
}

View File

@ -184,7 +184,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other)
QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation)
{
if (quintptr(data) & 3) {
qWarning() <<"QJsonDocument::fromRawData: data has to have 4 byte alignment";
qWarning("QJsonDocument::fromRawData: data has to have 4 byte alignment");
return QJsonDocument();
}

View File

@ -300,7 +300,7 @@ QJsonDocument Parser::parse(QJsonParseError *error)
{
#ifdef PARSER_DEBUG
indent = 0;
qDebug() << ">>>>> parser begin";
qDebug(">>>>> parser begin");
#endif
// allocate some space
dataLength = qMax(end - json, (ptrdiff_t) 256);
@ -346,7 +346,7 @@ QJsonDocument Parser::parse(QJsonParseError *error)
error:
#ifdef PARSER_DEBUG
qDebug() << ">>>>> parser error";
qDebug(">>>>> parser error");
#endif
if (error) {
error->offset = json - head;

View File

@ -72,7 +72,7 @@ public:
{
int fd = qt_safe_open("/pps/.all", O_RDONLY);
if (fd == -1) {
qWarning() << "qppsobject.cpp: qt_safe_open failed";
qWarning("qppsobject.cpp: qt_safe_open failed");
value = -1;
}
@ -114,7 +114,7 @@ QPpsAttributeMap QPpsObjectPrivate::decode(const QByteArray &rawData, bool *ok)
// no need to check ok in this case
attributeMap = decodeObject(&decoder, ok);
} else {
qWarning() << "QPpsObjectPrivate::decode: pps_decoder_initialize failed";
qWarning("QPpsObjectPrivate::decode: pps_decoder_initialize failed");
*ok = false;
}
@ -162,7 +162,7 @@ QPpsAttribute QPpsObjectPrivate::decodeString(pps_decoder_t *decoder)
pps_decoder_error_t error = pps_decoder_get_string(decoder, 0, &value);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeString: PPS_DECODER_GET_STRING failed";
qWarning("QPpsObjectPrivate::decodeString: PPS_DECODER_GET_STRING failed");
return QPpsAttribute();
}
@ -189,19 +189,19 @@ QPpsAttribute QPpsObjectPrivate::decodeNumber(pps_decoder_t *decoder)
case PPS_DECODER_CONVERSION_FAILED:
error = pps_decoder_get_int64(decoder, 0, &llValue);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeNumber: failed to decode integer";
qWarning("QPpsObjectPrivate::decodeNumber: failed to decode integer");
return QPpsAttribute();
}
flags = readFlags(decoder);
return QPpsAttributePrivate::createPpsAttribute(llValue, flags);
default:
qWarning() << "QPpsObjectPrivate::decodeNumber: pps_decoder_get_int failed";
qWarning("QPpsObjectPrivate::decodeNumber: pps_decoder_get_int failed");
return QPpsAttribute();
}
} else {
pps_decoder_error_t error = pps_decoder_get_double(decoder, 0, &dValue);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeNumber: pps_decoder_get_double failed";
qWarning("QPpsObjectPrivate::decodeNumber: pps_decoder_get_double failed");
return QPpsAttribute();
}
flags = readFlags(decoder);
@ -215,7 +215,7 @@ QPpsAttribute QPpsObjectPrivate::decodeBool(pps_decoder_t *decoder)
pps_decoder_error_t error = pps_decoder_get_bool(decoder, 0, &value);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeBool: pps_decoder_get_bool failed";
qWarning("QPpsObjectPrivate::decodeBool: pps_decoder_get_bool failed");
return QPpsAttribute();
}
@ -278,7 +278,7 @@ QPpsAttribute QPpsObjectPrivate::decodeData(pps_decoder_t *decoder)
case PPS_TYPE_NONE:
case PPS_TYPE_UNKNOWN:
default:
qWarning() << "QPpsObjectPrivate::decodeData: invalid pps_node_type";
qWarning("QPpsObjectPrivate::decodeData: invalid pps_node_type");
return QPpsAttribute();
}
}
@ -292,7 +292,7 @@ QPpsAttributeList QPpsObjectPrivate::decodeArray(pps_decoder_t *decoder, bool *o
// Force movement to a specific index.
pps_decoder_error_t error = pps_decoder_goto_index(decoder, i);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeArray: pps_decoder_goto_index failed";
qWarning("QPpsObjectPrivate::decodeArray: pps_decoder_goto_index failed");
*ok = false;
return QPpsAttributeList();
}
@ -319,7 +319,7 @@ QPpsAttributeMap QPpsObjectPrivate::decodeObject(pps_decoder_t *decoder, bool *o
// Force movement to a specific index.
pps_decoder_error_t error = pps_decoder_goto_index(decoder, i);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeObject: pps_decoder_goto_index failed";
qWarning("QPpsObjectPrivate::decodeObject: pps_decoder_goto_index failed");
*ok = false;
return QPpsAttributeMap();
}
@ -368,7 +368,7 @@ QVariant QPpsObjectPrivate::variantFromPpsAttribute(const QPpsAttribute &attribu
return variantMapFromPpsAttributeMap(attribute.toMap());
case QPpsAttribute::None:
default:
qWarning() << "QPpsObjectPrivate::variantFromPpsAttribute: invalid attribute parameter";
qWarning("QPpsObjectPrivate::variantFromPpsAttribute: invalid attribute parameter");
return QVariant();
}
}
@ -385,7 +385,7 @@ QByteArray QPpsObjectPrivate::encode(const QVariantMap &ppsData, bool *ok)
// The memory will be freed when pps_encoder_cleanup is called.
rawData = pps_encoder_buffer(&encoder);
if (!rawData) {
qWarning() << "QPpsObjectPrivate::encode: pps_encoder_buffer failed";
qWarning("QPpsObjectPrivate::encode: pps_encoder_buffer failed");
*ok = false;
}
}
@ -448,7 +448,7 @@ void QPpsObjectPrivate::encodeData(pps_encoder_t *encoder, const char *name, con
errorFunction = QStringLiteral("pps_encoder_add_null");
break;
default:
qWarning() << "QPpsObjectPrivate::encodeData: the type of the parameter data is invalid";
qWarning("QPpsObjectPrivate::encodeData: the type of the parameter data is invalid");
*ok = false;
return;
}
@ -685,7 +685,7 @@ QByteArray QPpsObject::read(bool *ok)
const int maxSize = ppsMaxSize->value;
if (maxSize == -1) {
qWarning() << "QPpsObject::read: maxSize is equal to -1";
qWarning("QPpsObject::read: maxSize is equal to -1");
safeAssign(ok, false);
return QByteArray();
}

View File

@ -105,7 +105,7 @@ inline bool QPpsObjectPrivate::decoderPush(pps_decoder_t *decoder, const char *n
{
pps_decoder_error_t error = pps_decoder_push(decoder, name);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeData: pps_decoder_push failed";
qWarning("QPpsObjectPrivate::decodeData: pps_decoder_push failed");
return false;
}
return true;
@ -115,7 +115,7 @@ inline bool QPpsObjectPrivate::decoderPop(pps_decoder_t *decoder)
{
pps_decoder_error_t error = pps_decoder_pop(decoder);
if (error != PPS_DECODER_OK) {
qWarning() << "QPpsObjectPrivate::decodeData: pps_decoder_pop failed";
qWarning("QPpsObjectPrivate::decodeData: pps_decoder_pop failed");
return false;
}
return true;

View File

@ -119,7 +119,7 @@ void QSystemSemaphorePrivate::cleanHandle()
if (::sem_close(semaphore) == -1) {
setErrorString(QLatin1String("QSystemSemaphore::cleanHandle (sem_close)"));
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << QLatin1String("QSystemSemaphore::cleanHandle sem_close failed.");
qDebug("QSystemSemaphore::cleanHandle sem_close failed.");
#endif
}
semaphore = SEM_FAILED;
@ -129,7 +129,7 @@ void QSystemSemaphorePrivate::cleanHandle()
if (::sem_unlink(QFile::encodeName(fileName).constData()) == -1 && errno != ENOENT) {
setErrorString(QLatin1String("QSystemSemaphore::cleanHandle (sem_unlink)"));
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << QLatin1String("QSystemSemaphore::cleanHandle sem_unlink failed.");
qDebug("QSystemSemaphore::cleanHandle sem_unlink failed.");
#endif
}
createdSemaphore = false;

View File

@ -153,7 +153,7 @@ void QSystemSemaphorePrivate::cleanHandle()
if (-1 == semctl(semaphore, 0, IPC_RMID, 0)) {
setErrorString(QLatin1String("QSystemSemaphore::cleanHandle"));
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << QLatin1String("QSystemSemaphore::cleanHandle semctl failed.");
qDebug("QSystemSemaphore::cleanHandle semctl failed.");
#endif
}
semaphore = -1;

View File

@ -101,7 +101,7 @@ void QSystemSemaphorePrivate::cleanHandle()
{
if (semaphore && !CloseHandle(semaphore)) {
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << QLatin1String("QSystemSemaphorePrivate::CloseHandle: sem failed");
qDebug("QSystemSemaphorePrivate::CloseHandle: sem failed");
#endif
}
semaphore = 0;
@ -116,7 +116,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
if (0 == ReleaseSemaphore(semaphore, count, 0)) {
setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore"));
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << QLatin1String("QSystemSemaphore::modifySemaphore ReleaseSemaphore failed");
qDebug("QSystemSemaphore::modifySemaphore ReleaseSemaphore failed");
#endif
return false;
}
@ -128,7 +128,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
#endif
setErrorString(QLatin1String("QSystemSemaphore::modifySemaphore"));
#if defined QSYSTEMSEMAPHORE_DEBUG
qDebug() << QLatin1String("QSystemSemaphore::modifySemaphore WaitForSingleObject failed");
qDebug("QSystemSemaphore::modifySemaphore WaitForSingleObject failed");
#endif
return false;
}

View File

@ -559,7 +559,7 @@ QList<QMimeType> QMimeBinaryProvider::allMimeTypes()
void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
{
#ifdef QT_NO_XMLSTREAMREADER
qWarning() << "Cannot load mime type since QXmlStreamReader is not available.";
qWarning("Cannot load mime type since QXmlStreamReader is not available.");
return;
#else
if (data.loaded)

View File

@ -55,7 +55,7 @@ void QCollatorPrivate::init()
LocaleRef localeRef;
int rc = LocaleRefFromLocaleString(locale.bcp47Name().toLocal8Bit(), &localeRef);
if (rc != 0)
qWarning() << "couldn't initialize the locale";
qWarning("couldn't initialize the locale");
UInt32 options = 0;
@ -73,7 +73,7 @@ void QCollatorPrivate::init()
&collator
);
if (status != 0)
qWarning() << "Couldn't initialize the collator";
qWarning("Couldn't initialize the collator");
dirty = false;
}

View File

@ -73,7 +73,7 @@ void QCollatorPrivate::init()
if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7)
collator |= SORT_DIGITSASNUMBERS;
else
qWarning() << "Numeric sorting unsupported on Windows versions older than Windows 7.";
qWarning("Numeric sorting unsupported on Windows versions older than Windows 7.");
}
if (ignorePunctuation)

View File

@ -909,7 +909,7 @@ template <class Key, class T>
void QMap<Key, T>::dump() const
{
const_iterator it = begin();
qDebug() << "map dump:";
qDebug("map dump:");
while (it != end()) {
const QMapNodeBase *n = it.i;
int depth = 0;
@ -922,7 +922,7 @@ void QMap<Key, T>::dump() const
<< it.key() << it.value();
++it;
}
qDebug() << "---------";
qDebug("---------");
}
#endif

View File

@ -131,7 +131,7 @@ void QTimeLinePrivate::setCurrentTime(int msecs)
const int transitionframe = (direction == QTimeLine::Forward ? endFrame : startFrame);
if (looping && !finished && transitionframe != currentFrame) {
#ifdef QTIMELINE_DEBUG
qDebug() << "QTimeLinePrivate::setCurrentTime: transitionframe";
qDebug("QTimeLinePrivate::setCurrentTime: transitionframe");
#endif
emit q->frameChanged(transitionframe, QTimeLine::QPrivateSignal());
}