From f485719012287cee0c9e5c6eb936d39092bba9b3 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 1 Oct 2018 19:48:28 +0200 Subject: [PATCH] kimg_rgb: optimize away QRegExp and QString::fromLocal8Bit. Summary: The code is even simpler this way. Found by using heaptrack. Test Plan: the unittest for rgb still passes. Reviewers: cfeck Reviewed By: cfeck Subscribers: jtamate, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D15890 --- src/imageformats/rgb.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/imageformats/rgb.cpp b/src/imageformats/rgb.cpp index 19e432d..a8a6eba 100644 --- a/src/imageformats/rgb.cpp +++ b/src/imageformats/rgb.cpp @@ -686,8 +686,8 @@ bool RGBHandler::canRead(QIODevice *device) return false; } - qint64 oldPos = device->pos(); - QByteArray head = device->readLine(64); + const qint64 oldPos = device->pos(); + const QByteArray head = device->readLine(64); int readBytes = head.size(); if (device->isSequential()) { @@ -699,10 +699,7 @@ bool RGBHandler::canRead(QIODevice *device) device->seek(oldPos); } - const QRegExp regexp(QLatin1String("^\x01\xda\x01[\x01\x02]")); - QString data(QString::fromLocal8Bit(head)); - - return data.contains(regexp); + return head.size() >= 4 && head.startsWith("\x01\xda\x01") && (head[3] == 1 || head[3] == 2); } ///////////////////////////////////////////////////////////////////////////////