summaryrefslogtreecommitdiffstats
path: root/src/plugins/imageformats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2010-03-11 13:03:14 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2010-03-11 13:04:48 (GMT)
commitaa351766d6cecd6cad43cb40596d3ae9166a9647 (patch)
tree7bcf2b346b8d8a07c7074fb452ae23d1221f2b2c /src/plugins/imageformats
parentbf521a9a5d7670944658e93fe462c72f800a04f1 (diff)
downloadQt-aa351766d6cecd6cad43cb40596d3ae9166a9647.zip
Qt-aa351766d6cecd6cad43cb40596d3ae9166a9647.tar.gz
Qt-aa351766d6cecd6cad43cb40596d3ae9166a9647.tar.bz2
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
Diffstat (limited to 'src/plugins/imageformats')
-rw-r--r--src/plugins/imageformats/jpeg/qjpeghandler.cpp6
1 files changed, 5 insertions, 1 deletions
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)