Skip to content

Commit

Permalink
eliminate some QString<->QByteArray round trips.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 committed Nov 3, 2024
1 parent fbc6732 commit f892a57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ class DebugLog
int flush();

private:
QString buf_;
QByteArray buf_;
};

void printposn(double c, bool is_lat);
Expand Down
12 changes: 6 additions & 6 deletions fatal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cstdio> // for vsnprintf
#include <cstdlib> // for exit

#include <QByteArray> // for QByteArray
#include <QDebug> // for QDebug
#include <QString> // for QString
#include <QtGlobal> // for qCritical, qDebug, qInfo, qWarning
Expand Down Expand Up @@ -101,13 +102,13 @@ int DebugLog::vlog(const char* fmt, va_list args1)
vsnprintf(cbuf, cbufsz, fmt, args2);
va_end(args2);

buf_.append(QString::asprintf("%s", cbuf));
buf_.append(cbuf);
delete[] cbuf;

int rc = 0;

for (auto idx = buf_.indexOf('\n'); idx >= 0; idx = buf_.indexOf('\n')) {
auto msg = buf_.sliced(0, idx + 1).toLocal8Bit();
QByteArray msg = buf_.sliced(0, idx + 1);
debug("%s", msg.constData());
rc += msg.size();
buf_.remove(0, idx + 1);
Expand All @@ -130,10 +131,9 @@ int DebugLog::flush()
int rc = 0;

if (!buf_.isEmpty()) {
auto msg = buf_.toLocal8Bit();
debug("%s", msg.constData());
rc += msg.size();
buf_ = QString();
debug("%s", buf_.constData());
rc += buf_.size();
buf_ = QByteArray();
}

return rc;
Expand Down

0 comments on commit f892a57

Please sign in to comment.