From 6ba6e7585dff4198aa3e4b23035ba95fb988400f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Aug 2021 19:12:10 +0200 Subject: [PATCH] QXpmHandler: clean up write_xpm_image: cut out the QBA middle-man MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of appending to a QByteArray and then streaming that one, just stream the components of a line directly. QTextStream's op<<(const char*) is not subject to QT_NO_CAST_FROM_ASCII, etc., so can be used unconditionally. Change-Id: Idd97a75a1b5b939de7176d40880a2f328d01927d Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/gui/image/qxpmhandler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index 22bfab684c..da975869d5 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -1168,13 +1168,12 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const } // write pixels, limit to 4 characters per pixel - QByteArray line; for (int y = 0; y < h; ++y) { - line.clear(); + s << ',' << Qt::endl << '\"'; const QRgb *yp = reinterpret_cast(image.constScanLine(y)); for (int x = 0; x < w; ++x) - line.append(xpm_color_name(cpp, colorMap[yp[x]])); - s << ',' << Qt::endl << '\"' << line << '\"'; + s << xpm_color_name(cpp, colorMap[yp[x]]); + s << '\"'; } s << "};" << Qt::endl; return (s.status() == QTextStream::Ok);