Remove temporary QStrings in HTTP output
There is no need to convert a QString from an QByteArray, the assignment of `Json::serialize()` becomes a fast move operation.
The temporary QString for *Content-Length* was removed (QTextStream  `operator<<`  supports writing integers).
@@ -17937,22 +17937,22 @@ int DeRestPlugin::handleHttpRequest(const QHttpRequestHeader &hdr, QTcpSocket *s
DBG_Printf(DBG_HTTP, "%s unknown request: %s\n", Q_FUNC_INFO, qPrintable(hdr.path()));
}
- QString str;
+ QByteArray str;
if (!rsp.map.isEmpty())
{
rsp.contentType = HttpContentJson;
- str.append(Json::serialize(rsp.map));
+ str = Json::serialize(rsp.map);
}
else if (!rsp.list.isEmpty())
{
rsp.contentType = HttpContentJson;
- str.append(Json::serialize(rsp.list));
+ str = Json::serialize(rsp.list);
}
else if (!rsp.str.isEmpty())
{
rsp.contentType = HttpContentJson;
- str = rsp.str;
+ str = rsp.str.toUtf8();
}
// some client may not be prepared for http return codes other than 200 OK
@@ -17964,12 +17964,12 @@ int DeRestPlugin::handleHttpRequest(const QHttpRequestHeader &hdr, QTcpSocket *s
stream << "HTTP/1.1 " << rsp.httpStatus << "\r\n";
stream << "Access-Control-Allow-Origin: *\r\n";
stream << "Content-Type: " << rsp.contentType << "\r\n";
- stream << "Content-Length: " << QString::number(str.toUtf8().size()) << "\r\n";
+ stream << "Content-Length: " << str.size() << "\r\n";
if (!rsp.hdrFields.empty())
{
- QList<QPair<QString, QString> >::iterator i = rsp.hdrFields.begin();
- QList<QPair<QString, QString> >::iterator end = rsp.hdrFields.end();
+ auto i = rsp.hdrFields.cbegin();
+ const auto end = rsp.hdrFields.cend();
for (; i != end; ++i)
{
