QLogging: avoid a needless check

QString::vasprintf() deals just fine with a nullptr format string,
so don't check manually.

The main advantage of dropping the check is that in two of three
cases, we can replace assignment with initialization, thus saving
one default ctor and one (move) assignment.

Change-Id: I08dd24111cd0b92f21ef9f1c3e352ede0f66afe0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2015-01-24 23:01:25 +01:00
parent 4b9a0c0a7c
commit bcfb535e82
1 changed files with 3 additions and 9 deletions

View File

@ -251,9 +251,7 @@ static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const cha
static void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg,
va_list ap, QString &buf)
{
if (msg)
buf = QString::vasprintf(msg, ap);
buf = QString::vasprintf(msg, ap);
qt_message_print(msgType, context, buf);
}
@ -1607,11 +1605,9 @@ void qErrnoWarning(const char *msg, ...)
{
// qt_error_string() will allocate anyway, so we don't have
// to be careful here (like we do in plain qWarning())
QString buf;
va_list ap;
va_start(ap, msg);
if (msg)
buf = QString::vasprintf(msg, ap);
QString buf = QString::vasprintf(msg, ap);
va_end(ap);
buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')');
@ -1623,11 +1619,9 @@ void qErrnoWarning(int code, const char *msg, ...)
{
// qt_error_string() will allocate anyway, so we don't have
// to be careful here (like we do in plain qWarning())
QString buf;
va_list ap;
va_start(ap, msg);
if (msg)
buf = QString::vasprintf(msg, ap);
QString buf = QString::vasprintf(msg, ap);
va_end(ap);
buf += QLatin1String(" (") + qt_error_string(code) + QLatin1Char(')');