From 726119c43156d9522b7f22a8bcc3521980e7d7a8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Aug 2021 16:42:07 +0200 Subject: [PATCH] QXpmHandler: clean up write_xpm_image: use conventional pointer arithmetic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... instead of *(array + index). Also fix a pointless cast from QRgb to int which the next line implicitly undoes (because colorMap has QRgb as key, not int) and get rid of the local variables that facilitated said fallacy in the first place. Change-Id: I71a92822ee2404646f6fb5533e40252f38e6b21f Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/gui/image/qxpmhandler.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index ae3fc8128d..501f3067fc 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -1133,8 +1133,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const for (int y = 0; y < h; ++y) { const QRgb *yp = reinterpret_cast(image.constScanLine(y)); for (int x = 0; x < w; ++x) { - QRgb color = *(yp + x); - const auto [it, inserted] = colorMap.try_emplace(color, ncolors); + const auto [it, inserted] = colorMap.try_emplace(yp[x], ncolors); if (inserted) ++ncolors; } @@ -1170,10 +1169,8 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const for (int y = 0; y < h; ++y) { line.clear(); const QRgb *yp = reinterpret_cast(image.constScanLine(y)); - for (int x = 0; x < w; ++x) { - int color = (int)(*(yp + x)); - line.append(xpm_color_name(cpp, colorMap[color])); - } + for (int x = 0; x < w; ++x) + line.append(xpm_color_name(cpp, colorMap[yp[x]])); s << ',' << Qt::endl << '\"' << line << '\"'; } s << "};" << Qt::endl;