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
This commit is contained in:
David Faure 2018-10-01 19:48:28 +02:00
parent 1db1b94657
commit f485719012

View File

@ -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);
}
///////////////////////////////////////////////////////////////////////////////