From aa351766d6cecd6cad43cb40596d3ae9166a9647 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 11 Mar 2010 14:03:14 +0100 Subject: Avoid unnecessary memory allocation in the jpeg handler's image detection The handler calls peek with 2 bytes to inspect the first two bytes. Instead of calling the overload of peek() that returns a new QByteArray with just two bytes, allocate 2 bytes on the stack and call the overload of peek() that writes into the specified buffer. Reviewed-by: Joao --- src/plugins/imageformats/jpeg/qjpeghandler.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index 6cb93ad..98bd88f 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -1188,7 +1188,11 @@ bool QJpegHandler::canRead(QIODevice *device) return false; } - return device->peek(2) == "\xFF\xD8"; + char buffer[2]; + if (device->peek(buffer, 2) != 2) + return false; + + return uchar(buffer[0]) == 0xff && uchar(buffer[1]) == 0xd8; } bool QJpegHandler::read(QImage *image) -- cgit v0.12